检测复选框状态更改 [英] detect checkbox state change
本文介绍了检测复选框状态更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检测用户是否选中或取消选中iframe中的复选框,并设置类似的标志.但是它似乎没有按预期工作.关于代码错误的任何指针吗?
I want to detect if user checks or unchecks a check box within an iframe and set a flag like so. But it does not seem to work as expected. Any pointers on the error on the code?
jQuery("#frameName").contents().find(":checkbox").bind('change', function(){
val = true;
alert("changed");
});
但是我可以检测是否通过使用复选框选中了
But I can detect if a checkbox is checked by using
var val = jQuery("#frameName").contents().find(":checkbox").is(":checked");
我希望能够检测到复选框上的任何状态变化并设置标志.
I want to be able to detect any state change on a checkbox and set the flag.
推荐答案
使用checked
DOM属性检查是否选中了复选框.即使选中该复选框,也会始终在更改时触发change
事件.
Use the checked
DOM property to check whether a checkbox is checked or not. The change
event is always triggered on change, even if the checkbox gets unchecked.
jQuery("#frameName").contents().find(":checkbox").bind('change', function(){
val = this.checked; //<---
alert("changed");
});
这篇关于检测复选框状态更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文