展开全部
Checkbox 控件又称为复选框控件,支持多选功能。同一组复选框控件需要有相同的name属性值。
1.checkbox 控件的属性。支持多数通用属。
它的特有属性有:indeterminate 。该属性是读写属性,可返回或设置复选框的状态。当设置该属性时,复选框处于选中状态,此时,该属性值与checked 无关。
indeterminate = true 或 indeterminate =false
2.checkbox 控件的事件
复选框控件支持多数通用事件,最常用的事件是click事件
以下是示例:
<html><head><title>演示 Checkbox 控件的使用</title>
<script language=vbscript type=text/vbscript>
<!--
sub chk1_onclick()
if chk1.checked then
textarea1.style.fontstyle="italic"
else
textarea1.style.fontstyle="normal"
end if
end sub
sub chk2_onclick()
if chk2.checked then
textarea1.style.fontweight="bold"
else
textarea1.style.fontweight="normal"
end if
end sub
sub chk3_onclick()
if chk3.checked then
textarea1.style.textdecorationunderline="true"
else
textarea1.style.textdecorationunderline="false"
end if
end sub
sub chk4_onclick()
if chk4.checked then
chk4.indeterminate=true
textarea1.style.textalign="center"
else
textarea1.style.textalign="left"
end if
end sub
-->
</script>
</head>
<body bgcolor="#ffffff">
<p align="center"><textarea rows=3 clos=35 id=textarea1 name=textarea1 style="font-family:宋体;font-size:18pt">演示 Checkbox 控件的使用</textarea></p>
<input type="checkbox" id="chk1" name=chktest />倾斜<br />
<input type="checkbox" id="chk2" name=chktest />加粗<br />
<input type="checkbox" id="chk3" name=chktest />下划线<br />
<input type="checkbox" id="chk4" name=chktest />居中<br />
</body></html>
1.checkbox 控件的属性。支持多数通用属。
它的特有属性有:indeterminate 。该属性是读写属性,可返回或设置复选框的状态。当设置该属性时,复选框处于选中状态,此时,该属性值与checked 无关。
indeterminate = true 或 indeterminate =false
2.checkbox 控件的事件
复选框控件支持多数通用事件,最常用的事件是click事件
以下是示例:
<html><head><title>演示 Checkbox 控件的使用</title>
<script language=vbscript type=text/vbscript>
<!--
sub chk1_onclick()
if chk1.checked then
textarea1.style.fontstyle="italic"
else
textarea1.style.fontstyle="normal"
end if
end sub
sub chk2_onclick()
if chk2.checked then
textarea1.style.fontweight="bold"
else
textarea1.style.fontweight="normal"
end if
end sub
sub chk3_onclick()
if chk3.checked then
textarea1.style.textdecorationunderline="true"
else
textarea1.style.textdecorationunderline="false"
end if
end sub
sub chk4_onclick()
if chk4.checked then
chk4.indeterminate=true
textarea1.style.textalign="center"
else
textarea1.style.textalign="left"
end if
end sub
-->
</script>
</head>
<body bgcolor="#ffffff">
<p align="center"><textarea rows=3 clos=35 id=textarea1 name=textarea1 style="font-family:宋体;font-size:18pt">演示 Checkbox 控件的使用</textarea></p>
<input type="checkbox" id="chk1" name=chktest />倾斜<br />
<input type="checkbox" id="chk2" name=chktest />加粗<br />
<input type="checkbox" id="chk3" name=chktest />下划线<br />
<input type="checkbox" id="chk4" name=chktest />居中<br />
</body></html>
展开全部
<div>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Text="游泳" OnCheckedChanged="CheckBox1_CheckedChanged1" /><br />
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox2_CheckedChanged"
Text="篮球" /><br />
<asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="True" Text="旅游" OnCheckedChanged="CheckBox3_CheckedChanged" /><br />
<asp:CheckBox ID="CheckBox4" runat="server" AutoPostBack="True" Text="足球" OnCheckedChanged="CheckBox4_CheckedChanged" /><br />
<asp:CheckBox ID="CheckBox5" runat="server" AutoPostBack="True" Text="阅读" OnCheckedChanged="CheckBox5_CheckedChanged" /><br />
<asp:CheckBox ID="CheckBox6" runat="server" AutoPostBack="True" Text="电影" OnCheckedChanged="CheckBox6_CheckedChanged" /> </div>
后台 代码为
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void show()
{
string result = "你选择的爱好有:";
if (CheckBox1.Checked == true) result += "游泳" + " ";
if (CheckBox2.Checked == true) result += "篮球" + " ";
if (CheckBox3.Checked == true) result += "旅游" + " ";
if (CheckBox4.Checked == true) result += "足球" + " ";
if (CheckBox5.Checked == true) result += "阅读" + " ";
if (CheckBox6.Checked == true) result += "电影" + " ";
Response.Write(result);
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
show();
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
show();
}
protected void CheckBox4_CheckedChanged(object sender, EventArgs e)
{
show();
}
protected void CheckBox5_CheckedChanged(object sender, EventArgs e)
{
show();
}
protected void CheckBox6_CheckedChanged(object sender, EventArgs e)
{
show();
}
protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
show();
}
}
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Text="游泳" OnCheckedChanged="CheckBox1_CheckedChanged1" /><br />
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox2_CheckedChanged"
Text="篮球" /><br />
<asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="True" Text="旅游" OnCheckedChanged="CheckBox3_CheckedChanged" /><br />
<asp:CheckBox ID="CheckBox4" runat="server" AutoPostBack="True" Text="足球" OnCheckedChanged="CheckBox4_CheckedChanged" /><br />
<asp:CheckBox ID="CheckBox5" runat="server" AutoPostBack="True" Text="阅读" OnCheckedChanged="CheckBox5_CheckedChanged" /><br />
<asp:CheckBox ID="CheckBox6" runat="server" AutoPostBack="True" Text="电影" OnCheckedChanged="CheckBox6_CheckedChanged" /> </div>
后台 代码为
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void show()
{
string result = "你选择的爱好有:";
if (CheckBox1.Checked == true) result += "游泳" + " ";
if (CheckBox2.Checked == true) result += "篮球" + " ";
if (CheckBox3.Checked == true) result += "旅游" + " ";
if (CheckBox4.Checked == true) result += "足球" + " ";
if (CheckBox5.Checked == true) result += "阅读" + " ";
if (CheckBox6.Checked == true) result += "电影" + " ";
Response.Write(result);
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
show();
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
show();
}
protected void CheckBox4_CheckedChanged(object sender, EventArgs e)
{
show();
}
protected void CheckBox5_CheckedChanged(object sender, EventArgs e)
{
show();
}
protected void CheckBox6_CheckedChanged(object sender, EventArgs e)
{
show();
}
protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
show();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
多个checkbox使用相同的name值即可,例如
<input type="checkbox" name="abc" value="1" />
<input type="checkbox" name="abc" value="2" />
<input type="checkbox" name="abc" value="3" />
如果需要id属性,id可以不同,不会影响多选.
<input type="checkbox" name="abc" value="1" />
<input type="checkbox" name="abc" value="2" />
<input type="checkbox" name="abc" value="3" />
如果需要id属性,id可以不同,不会影响多选.
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询