Chrome 选择输入点击事件替代方案(更改不能满足我的需要)

发布于 2024-12-02 15:34:40 字数 139 浏览 0 评论 0原文

当选择一个选择选项(包括重新选择)时,我需要触发一个事件。我在 ie/FF 中使用 click,但我意识到 webkit 浏览器没有 click 事件。更改对我不起作用,因为重新选择它时我也需要它。有没有办法可以实现此功能,或者我是否需要用某种组合小部件替换选择?

I need to fire an event when a select option is selected (including reselected). I was using click in ie/FF but I realized there is no click event for webkit browsers. Change will not work for me since I need it when it is reselected as well. Is there a way I can achieve this functionality or do I need to replace the select with some sort of combo widget?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

芯好空 2024-12-09 15:34:40

没有任何一个事件会在单击选项时被所有浏览器触发。在 IE 中,单击不更改选择的选项将根本不会触发任何事件。您可以在选择上捕捉 change 以及在选项上click 尝试在尽可能多的情况下获取事件,但不会 100% 。

如果您有一个下拉列表,其中单击某个选项即使已被选中也会产生效果,那么您所拥有的并不是真正的选择框。选择旨在从列表中选择一个选项,如果这不是您想要的,则不应将其标记为

相反,尝试一个充满按钮(用于操作)或链接(用于导航)的框,当您单击箭头按钮时会弹出。如果您愿意,您可以将其设计为看起来像选择。

There is no one event that will get fired by all browsers on an option click. In IE an option click that doesn't change the select will fire no events at all. You can catch change on the select as well as click on the option in an attempt to get the event in any many cases as possible, but it won't be 100%.

If you have a drop-down where clicking an option has an effect even if it was already selected, what you have isn't really a select box. Selects are designed to choose one option from a list and if that's not what you want you shouldn't mark it up as a <select>. Try to shoehorn a bunch of actions or navigation into a select box and you'll face a wide range of usability and accessibility issues.

Instead, try a box full of buttons (for actions) or links (for navigation), which pops up when you click on an arrow-button. You can style it to look like a select if you like.

独守阴晴ぅ圆缺 2024-12-09 15:34:40

您始终可以尝试使用 onmouseup 或 onfocus。

You could always try using onmouseup, or onfocus.

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