Microsoft Edge: onclick event stops working?(Microsoft Edge:onclick 事件停止工作?)
问题描述
我在 Microsoft Edge 中的 (ASP.NET) Web 应用程序有奇怪的问题.
I have strange problems with my (ASP.NET) web application in Microsoft Edge.
在某个时刻,onclick 事件停止工作.页面上响应 onclick 事件的所有按钮都停止工作.在同一页面上,我有一些响应 onmousedown 事件的按钮并且它们继续工作.
At a certain point the onclick event stops working. All buttons on the page that respond to the onclick event stop working. On the same page I have some buttons that respond to the onmousedown event and they keep working.
如果我刷新页面,问题就消失了.控制台中没有错误.我用其他浏览器(包括Windows 10下的IE11)没有这个问题.
If I refresh the page, the problem is gone. There are no errors in the console. I do not have this problem with other browsers (including IE11 under Windows 10).
你们中有人遇到过类似的问题吗?
Did any of you experience similar problems?
推荐答案
这不是一个完整的答案,因为它没有解决 为什么 click 事件不工作,但我觉得它属于这里,因为我和我的团队绝望地试图找到这个问题的答案.这似乎是 Edge 中的一个错误,我们尝试的所有解决方法都失败了,直到我偶然发现了上面的 @Come 评论.
This is not a complete answer, as it doesn't address why click events don't work, but I feel it belongs here, as my team and I were hopelessly stuck trying to find an answer to this question. It appears to be a bug in Edge, and every workaround we tried failed, until I stumbled upon @Come's comment above.
解决方案是将我们所有的 click 事件更改为 mouseup 事件,模拟相同的行为.出于某种原因,即使 click 没有触发,也触发了 mouseup.mousedown 也可以,但 mouseup 更恰当地模拟了 click.
The solution was to change all of our click events to mouseup events, emulating the same behavior. For some reason mouseup was triggered even when click wasn't. mousedown works as well, but mouseup more-properly emulates click.
var listenType = (navigator.userAgent.toLowerCase().indexOf('edge') != -1) ? 'mouseup' : 'click';
// ...
$("#my_element").on(listenType, function()
{
// ...
}
希望这对某人有所帮助!
Hopefully this helps someone!
这篇关于Microsoft Edge:onclick 事件停止工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Microsoft Edge:onclick 事件停止工作?
基础教程推荐
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
