checkBox的使用和事件监听

直接上代码:html

<!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>

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

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

就是这样~code

愉快的周五 : )htm

相关文章
相关标签/搜索