IE HTML 单选更改事件

发布于 2024-08-06 10:12:52 字数 200 浏览 2 评论 0原文

我有一个项目需要使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灯下孤影 2024-08-13 10:12:52

只是补充一下,您可以使用 onClick 事件强制 IE 触发 onChange 事件,因此如果允许使用 onClick 事件来触发更改事件,应该这样做:

<input type="radio" onclick="this.blur();"/>

Just to add, you can force IE to trigger the onChange event using the onClick event, so if you are allowed use the onClick event to trigger the change event, this should do it:

<input type="radio" onclick="this.blur();"/>
云淡月浅 2024-08-13 10:12:52

我有同样的问题。我发现的唯一选择是:

  1. 使用一个 js 框架来整合所有浏览器的特性(你会想要这样做,相信我。你在 Safari 中测试过你的页面了吗?)

  2. 如果你需要触发事件但不这样做不想使用onclick,请使用onfocusonblur。如果您对其他无线电使用onblur,则效果几乎相同。

I had the same exact issue. The only options I found were:

  1. 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?)

  2. If you need the event to trigger but don't want to use onclick, use onfocus or onblur. If you use onblur for the OTHER radios, it is almost identical.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文