checkBox的使用和事件监听

直接上代码:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
    <script>
        function onClickHander(obj){
            if(obj.checked){
                console.log("selected");
            }else{
                console.log("unselected");
            }
            
        }
    </script>
<body>
    <input id="checkBox" type="checkbox" onclick="onClickHander(this)"></input>
</body>
</html>

1、绑定事件时记得加上this,把节点对象传入;

2、利用节点的checked属性,可判断当前是否已选中。

就是这样~

愉快的周五 : )

posted @ 2016-07-01 17:28  xiao小孔  阅读(24781)  评论(0编辑  收藏  举报