当前位置:编程学习 > JS >>

jquery checkbox全选,取消操作

jQuery的选择器确实很强大,比起自己实现能节约不少代码,下面我们来看看checkbox全选,取消代码,有需要的朋友可以参考一下。
判断checkbox是否被选中

var chkBind = $("#chkBind").attr('checked');

checkbox全选,取消

$("#chkSelectAll").click(function() {
    var flag = $(this).attr("checked");
    $("[name=chkItem]:checkbox").each(function() {
    $(this).attr("checked", flag);
  })
});

实例

<script type="text/网页特效">
$(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="取消全选" />

补充:网页制作,jquery 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,