IE HTML 单选更改事件
我有一个项目需要使用 JavaScript 从 HTML 单选更改事件更新一些值。
由于某些原因,在 IE 中,似乎只有当无线电失去焦点时才会调用 onchange 事件。不幸的是,由于代码的设置方式,我无法使用单击事件,而必须使用更改事件。
有谁知道如何强制 IE 在检查更改后立即引发更改事件,而不是在失去焦点时引发更改事件?
谢谢。
I have a project that requires some values to get updated with JavaScript from an HTML radio change event.
For some reason in IE, it seems that the onchange event isn't called until the radio has lost focus. Unfortunately due to the way the code is setup, I can't use the click event and have to use the change event.
Does anyone know of a way to force IE to raise the change event as soon as the check is changed rather than when it looses focus?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是补充一下,您可以使用
onClick
事件强制 IE 触发onChange
事件,因此如果允许使用onClick
事件来触发更改事件,应该这样做:Just to add, you can force IE to trigger the
onChange
event using theonClick
event, so if you are allowed use theonClick
event to trigger the change event, this should do it:我有同样的问题。我发现的唯一选择是:
使用一个 js 框架来整合所有浏览器的特性(你会想要这样做,相信我。你在 Safari 中测试过你的页面了吗?)
如果你需要触发事件但不这样做不想使用
onclick
,请使用onfocus
或onblur
。如果您对其他无线电使用onblur
,则效果几乎相同。I had the same exact issue. The only options I found were:
Use a js framework that consolidates all of the browser to browser idiosyncrasies (you're going to want to do this, trust me. Have you tested your page in Safari yet?)
If you need the event to trigger but don't want to use
onclick
, useonfocus
oronblur
. If you useonblur
for the OTHER radios, it is almost identical.