选择单选按钮的事件? [英] Event for radio button being selected?
问题描述
是否有选择单选按钮的事件?
Is there some event for a radio button being selected?
我知道我可以使用点击但我相信可以在某些浏览器中设置单选按钮的样式单击单选按钮的外部区域可能不会选择单选按钮。
I know I can use "click" but I believe it is possible to style radio buttons in some browsers such that clicking an outter area of a radio button might not select the radio button.
我应该使用什么事件?
推荐答案
这取决于您何时想要了解该事件。
It depends when you want to be informed of the event.
如果您想立即知道,请使用点击
。 IE在调用处理程序函数之前更新 checked
的状态,并且认为其他浏览器也会这样做。您可能需要仔细检查,因为我现在只能使用IE浏览器。
If you want to know immediately, go with click
. IE updates the state of checked
before the handler function is called, and I think the other browsers do as well. You may want to double check as I only have IE to work with right now.
如果您只是在事情发生之前需要知道,您可以使用变化
。 IE将不会触发更改
事件,直到所选单选按钮失去焦点。 FF / chrome /其他人可能会在不改变焦点的情况下触发事件,但我相信IE在这种情况下实际上是正确的。
If you only need to know before something else happens, you can use change
. IE will not fire the change
event until the selected radio button loses focus. FF/chrome/others may fire the event without focus changing, but I believe IE is actually doing it right in this case.
这篇关于选择单选按钮的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!