js判断单选框checkbox是否选中
墨初 Web前端 1283阅读
收集了两个 checkbox 单选择框在js或jq中的选中与未选中的事件,供大家参考!
js下 checkbox 选中与未选中事件
示例代码:
<label><input type="checkbox" onclick="oncheckBox(this)" />73so.com</label>
<script>
function oncheckBox(e)
{
if(e.checked == true){
alert('已选中');
}else{
alert('未选中');
}
}
</script>jquery 下 checkbox 选中与未选中事件
示例代码:
<label><input type="checkbox" name="host" />73so.com</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){
console.log("选中");
}else{
console.log("不选中");
}
});
</script>