直接上代碼:
<!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屬性,可判斷當前是否已選中。
就是這樣~
愉快的周五 : )
