简体   繁体   English

为什么 IE8 在页面加载时运行 jQuery.click 函数?

[英]Why is IE8 running a jQuery.click function on page load?

$('.consejosTab').live("click", function(){
    window.location = 'http://encuentratrabajoonline.es/consejos/';
    console.log('clicked')
});

Can anyone explain to me what this code is being initialized on page load, but only in IE8?任何人都可以向我解释此代码在页面加载时初始化的内容,但仅在 IE8 中? I've disabled all triggers and confirmed that there are no other click functions being run that could be interfering with this.我已禁用所有触发器并确认没有其他正在运行的点击功能可能会干扰此功能。 This code sits within a document.ready, and is the only click function that seems to trigger on the page load.此代码位于 document.ready 中,并且是似乎在页面加载时触发的唯一点击函数。

EDIT:编辑:

In an interesting twist, in IE8 the event.target for the click function is the window.有趣的是,在 IE8 中,单击函数的 event.target 是窗口。 In IE8 it returns as the URL for the page, but in everything else it appears as the actual element that it was clicked on?在 IE8 中,它作为页面的 URL 返回,但在其他所有内容中,它显示为它被点击的实际元素?

A good way to troubleshoot this is to log the element that was clicked.解决此问题的一个好方法是记录被单击的元素。

$('.consejosTab').live("click", function(evt){
    console.log(evt.target);
});

You will then be able to see what element is being clicked (and the page won't reload).然后您将能够看到正在单击的元素(并且页面不会重新加载)。 I assume you have more than one element labeled consejosTab.我假设您有多个标记为 consejosTab 的元素。

You can also put a breakpoint on that console.log line, and browse through the call stack.您还可以在该 console.log 行上放置一个断点,并浏览调用堆栈。

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

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