javascript判断CheckBoxList必须选中一个
<asp:CheckBoxList ID= "chkListPro " runat= "server " RepeatColumns= "2 " Width= "282px " Font-Size= "12px ">
</asp:CheckBoxList>
CheckBoxList数据源已绑定
是CheckBoxList,不要整一堆百度上的那些input,不好使
------解决方案--------------------这个好像得写在Button_Click中吧
chkListPro.Attribute.Add( "onclick ", "judge() ");
------解决方案--------------------function bool judge(){
if(doucument.GetElementById( 'checkbox1 ').value== ' '&&doucument.GetElementById(checkbox2).value== ' ')
return false;
return true;
}
------解决方案--------------------弄半天没弄出来。。。。
帮顶,一起学吧
------解决方案--------------------可以用RequiredFieldValider控件,效果比js更好
------解决方案--------------------为什么要用JS啊,做循环,看CheckListBox的Item里是否有被选中的
------解决方案-------------------- <body MS_POSITIONING= "GridLayout ">
<form id= "Form1 " method= "post " runat= "server ">
<input type=checkbox id=111 value= '111 '>
<input type=checkbox id=222 value= '222 '>
<SCRIPT>
function CheckSelect(frm)
{
for(var i=0;i <frm.elements.length;i++)
{
var e = frm.elements[i];
if(e.type == 'checkbox ')
{
if(e.checked)
{
return;
}
}
}
alert( '至少选择一个 ');
}
</SCRIPT>
<input type= "button " onclick= "CheckSelect(this.form) " value= "检查 ">
</form>
</body>
------解决方案--------------------学习
------解决方案-------------------- <script type= "text/javascript ">
function btnClick()
{
var list = document.getElementById( "chkList ");
var j = 0;
for(var i = 0 ; i < list.rows.length;i++)
{
var chk = list.rows[i].childNodes[0].childNodes[0];
if (chk.checked)
{
j++;
}
}
return (j > 0);
}
</script>
<asp:Button ID= "btn " Text= "button " runat= "server "/>
<asp:CheckBoxList ID= "chkList " runat= "server ">
<asp:ListItem Text= "1 " Value= "1 "> </asp:ListItem>
<asp:ListItem Text= "2 " Value= "2 "> </asp:ListItem>
<asp:ListItem Text= "3 " Value= "3 "> </asp:ListItem>
<asp:ListItem Text= "4 " Value= "4 "> </asp:ListItem>
</asp:CheckBoxList>
protected void Page_Load(object sender, EventArgs e)