js下 checkbox 选中与未选中事件
墨初 前端设计 14588阅读
写了两个关于 checkbox 选择框在JS脚本下的选中与未选中事件,大家做个参考吧!
js下 checkbox 选中与未选中事件
示例代码:
<label><input type="checkbox" onclick="OncheckBox(this)" />飞鸟慕鱼博客</label> <script> function OncheckBox(e) { if(e.checked == true){ alert('已选中'); }else{ alert('未选中'); } } </script>
代码示例:
jquery 下 checkbox 选中与未选中事件
示例代码:
<!-- 飞鸟慕鱼博客 http://feiniaomy.com --> <label><input type="checkbox" name="host" />飞鸟慕鱼博客</label> <script src="https://cdn.staticfile.org/jquery/2.2.4/jquery.min.js"></script> <script> $('input[name="host"]').on('click',function(){ if ($(this).checked == true){ alert("选中"); }else{ alert("不选中"); } }); </script>