jquery中如何判断在一组checkbox中至少有一个被选中以阻止表单被提交?
Html如下:
<table id="ctl00_ContentPlaceHolder_ChkBoxListArchiveDept" border="0">
<tr>
<td><input id="ctl00_ContentPlaceHolder_ChkBoxListArchiveDept_0" type="checkbox" name="ctl00$ContentPlaceHolder$ChkBoxListArchiveDept$0" /><label for="ctl00_ContentPlaceHolder_ChkBoxListArchiveDept_0">a</label></td>
</tr><tr>
<td><input id="ctl00_ContentPlaceHolder_ChkBoxListArchiveDept_1" type="checkbox" name="ctl00$ContentPlaceHolder$ChkBoxListArchiveDept$1" /><label for="ctl00_ContentPlaceHolder_ChkBoxListArchiveDept_1">b</label></td>
</tr>
       ....略
</table>

解决方案 »

  1.   


    <script src="js/jquery-1.3.2.js"></script>
    <script language="javascript"> 
    function check(){
    var a = $(":checkbox:checked");
    if(a.length < 1) alert("至少选一个")
    }
    </script> 
    <input type="button" onclick="check();" value="click">
    <table id="ctl00_ContentPlaceHolder_ChkBoxListArchiveDept" border="0"> 
    <tr> 
    <td> <input id="ctl00_ContentPlaceHolder_ChkBoxListArchiveDept_0" type="checkbox" name="ctl00$ContentPlaceHolder$ChkBoxListArchiveDept$0" /> <label for="ctl00_ContentPlaceHolder_ChkBoxListArchiveDept_0">a </label> </td> 
    </tr> <tr> 
    <td> <input id="ctl00_ContentPlaceHolder_ChkBoxListArchiveDept_1" type="checkbox" name="ctl00$ContentPlaceHolder$ChkBoxListArchiveDept$1" /> <label for="ctl00_ContentPlaceHolder_ChkBoxListArchiveDept_1">b </label> </td> 
    </tr> 
    </table>