jQuery实现checkbox全选
2007-11-08 22:57 | Filed Under Html/JS/CSS |
jQuery的选择器确实很强大,比起自己实现能节约不少代码
- <script type="text/javascript">
- $(function() {
- $("#selectall").click(function() {
- $("input[@name='shareuser[]']").each(function() {
- $(this).attr("checked", true);
- });
- });
- $("#deselectall").click(function() {
- $("input[@name='shareuser[]']").each(function() {
- $(this).attr("checked", false);
- });
- });
- });
- </script>
- <input type='checkbox' id='in-shareuser-10' name='shareuser[]' value='10' />UserA
- <input type='checkbox' id='in-shareuser-11' name='shareuser[]' value='11' />UserB
- <input type='checkbox' id='in-shareuser-12' name='shareuser[]' value='12' />UserC
- <input type="button" id="selectall" name="selectall" value="全选" />
- <input type="button" id="deselectall" name="deselectall" value="取消全选" />
相关日志


