Microsoft Edge:onclick 事件停止工作? [英] Microsoft Edge: onclick event stops working?

查看:41
本文介绍了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 事件停止工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆