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屬性,可判斷當前是否已選中。

就是這樣~

愉快的周五 : )


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM