直接上代碼: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