现在的位置: 首页 > 综合 > 正文

查找checkbox是否被选中

2018年04月09日 ⁄ 综合 ⁄ 共 466字 ⁄ 字号 评论关闭

function CheckThisForm()
{
var thisForm = document.forms[0];
var j = 0;
for(i=0;i<thisForm.length;i++)
{
if(thisForm.elements[i].name.indexOf("CheckBox")!=-1)
{
if (thisForm.elements[i].checked)
{
j++;
}
}
}
alert(j);
}

<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:CheckBox ID="CheckBox2" runat="server" />
<asp:CheckBox ID="CheckBox3" runat="server" />
<input id="Button1" type="button" value="button" onclick="CheckThisForm()" />
</form>

不过要保证这些checkbox的id要有一定的规律,可以试一下  

抱歉!评论已关闭.