简体   繁体   English

Microsoft Edge:onclick事件停止工作?

[英]Microsoft Edge: onclick event stops working?

I have strange problems with my (ASP.NET) web application in Microsoft Edge. 我在Microsoft Edge中的(ASP.NET)Web应用程序有奇怪的问题。

At a certain point the onclick event stops working. 在某一点上, onclick事件停止工作。 All buttons on the page that respond to the onclick event stop working. 页面上响应onclick事件的所有按钮都停止工作。 On the same page I have some buttons that respond to the onmousedown event and they keep working. 在同一页面上,我有一些按钮响应onmousedown事件并继续工作。

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). 我没有其他浏览器(包括Windows 10下的IE11)的这个问题。

Did any of you experience similar problems? 你们有没有遇到过类似的问题?

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. 这不是一个完整的答案,因为它没有解决为什么 click事件不起作用,但我觉得它属于这里,因为我的团队和我无可救药地试图找到这个问题的答案。 It appears to be a bug in Edge, and every workaround we tried failed, until I stumbled upon @Come's comment above. 它似乎是Edge中的一个错误,我们尝试过的每一个解决方法都失败了,直到我偶然发现了@ Come的评论。

The solution was to change all of our click events to mouseup events, emulating the same behavior. 解决方案是将所有click事件更改为mouseup事件,模拟相同的行为。 For some reason mouseup was triggered even when click wasn't. 由于某种原因,即使没有click也会触发mouseup mousedown works as well, but mouseup more-properly emulates click . mousedown也可以,但是mouseup更好地模拟click

var listenType = (navigator.userAgent.toLowerCase().indexOf('edge') != -1) ? 'mouseup' : 'click';

// ...

$("#my_element").on(listenType, function() 
{
    // ...
}

Hopefully this helps someone! 希望这有助于某人!

This is a bug in Edge. 这是Edge中的一个错误。

What I've found is that it's related to both popping up a child window and rearranging(or modifying) tr's in a table. 我发现它与弹出子窗口和重新排列(或修改)表中的tr有关。

https://connect.microsoft.com/IE/feedback/details/2109810/browser-stops-registering-click-events-on-table https://connect.microsoft.com/IE/feedback/details/2109810/browser-stops-registering-click-events-on-table

To fix this, you have to force the table to redraw. 要解决此问题,您必须强制重绘表。 You can do this by setting display:none before modifying the table, and then setting display:previousValue after changing it. 您可以通过在修改表之前设置display:none,然后在更改后设置display:previousValue来完成此操作。

Hope this helps. 希望这可以帮助。

我的修复方法是创建一个“隐藏”的输入元素,并将焦点调用到它上面,这会奇怪地使点击返回。

In my case, removing child elements bring this problem. 就我而言,删除子元素会带来这个问题。 Therefore when I remove the element (including replace DOM by innerHTML), I make style.display = "none" for the element before removing. 因此,当我删除元素(包括用innerHTML替换DOM)时,我会在删除之前为该元素创建style.display = "none" This resolves the issue. 这解决了这个问题。

For example, I use this function 例如,我使用此功能

function removeComponent(selector) {
  $(selector).css("display", "none");
  return $(selector).detach();
}

instead of 代替

function removeComponent(selector) {
  return $(selector).detach();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM