javascript 使用javascript选中/选择单选框/复选框按钮时的“oncheck”事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9531491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 06:59:46  来源:igfitidea点击:

Radio/checkbox buttons "oncheck" event when is checked/selected with javascript

javascriptcheckbox

提问by Ivan G

How to detect the moment when a radio/checkbox button is checked with javascript?

如何检测使用 javascript 检查单选框/复选框按钮的时刻?

Ex:

前任:

document.getElementById("myRadioButton").checked = true

Is there a method to detect the state change of "myRadioButton" and atach a handler?

有没有一种方法可以检测“myRadioButton”的状态变化并附加处理程序?

I need it specially for Internet Explorer 6+.

我特别需要它用于 Internet Explorer 6+。

采纳答案by Ivan G

Finally I found a solution, the event that triggers then radio/checkbox buttons are checked with javascript(and not only) is called onpropertychangein ie and DOMAttrModifiedin firefox

最后我找到了一个解决方案,在 ie 中调用onpropertychange并在 firefox 中调用DOMAttrModified