Opera 在禁用的输入元素上触发鼠标事件
我有一个图像元素,以下是按钮的 html
<input type="image"src="images/undo.png" onmouseover="this.src='images/undo-hover.png'" onmouseout="this.src='images/undo.png'" id="btn_back" onClick="back();" >
当我的应用程序禁用此输入(属性disabled =“disabled”)时,所有浏览器都会停止触发鼠标事件。所以我没有得到悬停图像。但歌剧仍然继续触发这些事件,并且我不断在禁用元素上获取悬停图像。
I have an image element, following is the html for the button
<input type="image"src="images/undo.png" onmouseover="this.src='images/undo-hover.png'" onmouseout="this.src='images/undo.png'" id="btn_back" onClick="back();" >
When my application makes this input disabled (attribute disabled="disabled") all browsers stop firing mouse events. So I don't get hover images. But opera still keeps firing these event, and I keep getting the hover images on disabled elements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您能否尝试默认禁用 INPUT 元素(从一开始就在 INPUT 标记中添加禁用=“disabled”)。然后查看 Opera 是否仍在响应鼠标悬停。这可能无法立即解决问题,但有助于找出原因。
另外,另一种方法可能是在鼠标事件上调用 JS 函数并检查该元素是否被禁用。如果它被禁用,则不要更改 src 属性。
哈特哈,
Can you please try making the INPUT element disabled by default (add disabled="disabled" in the INPUT tag from start). Then see if Opera is still responding to mouse hover. This may not fix the issue right away but will help in figuring out the cause.
Also, another approach could be to call the JS function on mouse event and check if the element is disabled or not. If it is disabled then dont change the src attribute.
HTH,
这是 Opera 中的一个错误,因为我们显然正在做一些与其他浏览器不同的事情。请在 https://bugs.opera.com/wizard/ 上报告并提供错误 ID 。
也就是说,我不认为你所依赖的东西在任何地方都是标准化的,所以你可能不应该编写依赖于这种有点奇怪的行为的代码。 “disabled”属性仅意味着该元素在单击时不会执行其正常操作。我真的不明白为什么设置禁用应该阻止触发鼠标悬停/移动。通过 JS 可以很容易地检查按钮是否被禁用,如果被禁用则不交换图像。
this is a bug in Opera as we're apparently doing something different than other browsers. Please report it on https://bugs.opera.com/wizard/ and give me the bug ID.
That said, I don't think what you are relying on is standardised anywhere, so possibly you should not write code that depends on this somewhat quirky behaviour. The "disabled" attribute merely means that the element will not do its normal action when clicked. I don't really see any reason why setting disabled should prevent firing mouseover/move. It's easy to check from JS if the button is disabled and not swap the image if it is.
这似乎是歌剧中的预期行为,请参阅以下链接。
http://www.quirksmode.org/dom/events/click.html
它说“在 Firefox 和 Safari 中,禁用的表单字段上的单击事件不会触发事件。Opera 会触发 mousedown 和 mouseup 事件,但不会触发 click 事件。IE 在表单上触发 mousedown 和 mouseup,但不会触发 click 事件。所有这些实现被考虑 正确的。”
谢谢,
乌尼克里希南 B.
It seems like an expected behavior in opera, Please see the following link.
http://www.quirksmode.org/dom/events/click.html
It says that "A click event on a disabled form field does not fire events in Firefox and Safari. Opera fires the mousedown and mouseup events, but not the click event. IE fires mousedown and mouseup, but not click, on the form. All these implementations are considered correct."
Thanks,
Unnikrishnan B.