如何使用jquery一键检查复选框(3) [英] how to make a checkboxes(3) checked at one click using jquery
本文介绍了如何使用jquery一键检查复选框(3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我有一堆复选框,
说,如果我点击任何复选框,我还要勾选下两个复选框(即旁边两个)
say, if i clicked on any checkbox, i want make checked next two checkboxes also (i.e, beside two)
<table border="1" cellspacing="0" width="450">
<tr>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
</tr>
</table>
任何人都可以帮助我,
提前致谢。
推荐答案
试试这个它有你想要的切换效果。
Try this it has toggle effect as you want.
这是脚本:
$(':checkbox').click(function () {
if ($(this).is(":checked")) {
$(this).parent().nextAll("td").slice(0, 2).find(":checkbox").prop('checked', true);
}
else {
$(this).parent().nextAll("td").slice(0, 2).find(":checkbox").prop('checked', false);
}
});
这是工作 DEMO
这篇关于如何使用jquery一键检查复选框(3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文