开发者

How can you determine if a radio button was set checked=true by 3rd party JavaScript?

开发者 https://www.devze.com 2023-04-07 09:00 出处:网络
Setting a radio button to checked=true programatically doesn\'t fire a change event. How can I know if a开发者_如何学Python radio button was checked by a script?

Setting a radio button to checked=true programatically doesn't fire a change event. How can I know if a开发者_如何学Python radio button was checked by a script?

See this example: http://jsfiddle.net/wykEx/7/

In Firebug, no change events are logged to the console unless you manually click on the radio buttons.


One way to do it would be to set up a timer and poll for changes. Of course it may not be the most elegant solution but it should be good enough and should work in all browsers.

The biggest caveat with doing it this way is that you may loose some transitions if code changes the checked attribute of your input element too often.

window.setInterval(function(){
    var elem = $('twoRadioBtn');
    if(elem.checked != elem.lastchecked)
    {
        console.log('TWO changed!');

        elem.lastchecked = elem.checked;
    }
}, 100);        // poll every 100 ms.
0

精彩评论

暂无评论...
验证码 换一张
取 消