selected对话框全选

selected对话框全选

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="checklist">
    <input type="checkbox" value="1" /> 篮球
    <input type="checkbox" value="2" /> 足球
    <input type="checkbox" value="3" /> 羽毛球
</div>
<div>
    <input type="button" value="全选" id="selectall">
    <input type="button" value="不选" id="unselect">
    <input type="button" value="反选" id="reverseall">
</div>

<script type="text/javascript" src="jquery-2.2.3.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#selectall").click(function () {
            $("#checklist :checkbox").attr('checked',true)
            //$("#checklist").children("input[type='checkbox']").attr('checked',true)
        })

        $("#unselect").click(function () {
        $("#checklist input[type='checkbox']").attr('checked',false)
          //  $("#checklist").children("input[type='checkbox']").attr('checked',false)
        })
    })

</script>
</body>
</html>

 

posted @ 2016-04-14 12:17  fengjian1585  阅读(228)  评论(0编辑  收藏  举报