我想在选中同一行中的两个复选框时弹出错误消息/提醒。我已经能够统计复选框的总数,并且我知道如何计算当前有多少个复选框。我的每个复选框都有一个唯一的ID。检查是否选中同一行中的复选框
<body>
<table id="tester">
<tr>
<td width="100" id="A1" ><label><input type="checkbox" name="A" value=1 id="A1" /> A1</label></td>
<td width="100" id="B1" ><label><input type="checkbox" name="B" value=1 id="B1" /> B1</label></td>
</tr>
<tr>
<td width="100" id="A2" ><label><input type="checkbox" name="A" value=1 id="A2" /> A2</label></td>
<td width="100" id="B2" ><label><input type="checkbox" name="B" value=1 id="B2" /> B2</label></td>
</tr>
</table>
<input id="clickMe" type="button" value="clickme" onclick="test();" />
</body>
我的jQuery技能非常基础。这里是我用来计算方框和计数选中框的代码。
$(document).ready();
var len = $('input:checkbox').length;
console.log("There are "+len+" checkboxes");
var count2;
var test = function(){
var count2 = $("[type='checkbox']:checked").length;
console.log("There are "+count2+" checked checkboxes");
};
任何帮助将是伟大的,谢谢!
伟大的思想.... – cgTag