简体   繁体   English

在document.body上的Click事件无法在IE8上正常运行

[英]Click event on document.body not working as it should on IE8

I'm working on some tweaks for a webpage, I'm using MVC and jquery. 我正在对网页进行一些调整,正在使用MVC和jquery。

Basically I have some help icons on my page, when the user clicks on the icon, a bubble appears with a help description. 基本上,我的页面上有一些帮助图标,当用户单击该图标时,会出现一个带有帮助说明的气泡。

I have this code in my javascript for that page: 我在该页面的javascript中有以下代码:

AddHelpIconMouseEvents: function(element, msg, divForm) {
   $(element).live('click', function(event) {
      if (event.type === "click") MyClassHelper.showHelpIconBubble(msg, divForm, event);
   });
   $(document.body).click(function() { $(divForm).hide('fast'); });            
}

As you can see I'm using the document.body.click event to capture any click outside the help bubble, and hide the bubble. 如您所见,我正在使用document.body.click事件捕获帮助提示框之外的所有点击,并隐藏提示框。

Now consider this situation, I click on the help icon and the bubble is displayed, if I click anywhere else on the page, the bubble disappears as expected, but the problem I have is, if instead of clicking on a blank space on the page I click on a link, the link displays another section of the page, hides the section that contained the help icon but the help bubble does not disappear, it remains displayed. 现在考虑这种情况,我单击帮助图标,然后显示气泡,如果我单击页面上的其他任何位置,气泡将按预期消失,但是我遇到的问题是,如果不是单击页面上的空白我单击一个链接,该链接显示页面的另一部分,隐藏包含帮助图标的部分,但帮助提示框并没有消失,它仍然显示。

This doesn't happen on Firefox, in which I can click on a link or on an empty space and the bubble disappear. 在Firefox上不会发生这种情况,在Firefox中,我可以单击链接或空白区域,气泡消失。

I think this may be related to the way in which IE handle events, I think I read something about it, so I wonder if anyone knows how can I fix this, I think I can put some code on the links and validate if the bubble is visible, hide it, but I don't like the idea, I think it is not a good solution, I wonder if there is another better way to handle this. 我认为这可能与IE处理事件的方式有关,我想我对此有所了解,所以我想知道是否有人知道如何解决此问题,我想我可以在链接上放置一些代码并验证气泡是否有效是可见的,可以隐藏它,但是我不喜欢这个主意,我认为这不是一个好的解决方案,我想知道是否还有另一种更好的方法来解决这个问题。

Thanks, 谢谢,

You can make a function which checks for the help bundle to check in DOM if it already exists. 您可以创建一个函数来检查帮助捆绑包,以在DOM中检查它是否已经存在。 If so remove it from DOM. 如果是这样,请将其从DOM中删除。 You have to call this function on every other link. 您必须在其他所有链接上调用此函数。

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

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