checkBox的使用和事件监听
Posted Life is experience, 功不唐捐,终生学习~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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属性,可判断当前是否已选中。
就是这样~
愉快的周五 : )
以上是关于checkBox的使用和事件监听的主要内容,如果未能解决你的问题,请参考以下文章