简体   繁体   English

两次单击相同事件处理程序

[英]Same Click Event Handler Registering Twice

I'm trying to solve a Bootstrap ScrollSpy issue where clicking the tab links is not doing anything (though scrolling properly highlights the tabs). 我正在尝试解决Bootstrap ScrollSpy问题,其中单击选项卡链接没有任何作用(尽管正确滚动会突出显示选项卡)。 I noticed that the same Bootstrap click event handler is showing up twice in Chrome Developer Tools (I've verified that if I click on each of the links, it brings me to the same line in the same file). 我注意到,相同的Bootstrap单击事件处理程序在Chrome开发者工具中显示了两次(我已经确认,如果单击每个链接,它将带我到同一文件的同一行)。

Why would the same exact click handler be appearing twice? 为什么相同的确切点击处理程序会出现两次? I've also verified that Bootstrap is only being included once. 我还验证了Bootstrap仅被包含一次。

在此处输入图片说明

Try clicking that bootstrap.js link that you're pointing to in your screenshot, and adding a line-of-code breakpoint on the line that registers the event listener. 尝试单击您在屏幕快照中指向的bootstrap.js链接,然后在注册事件侦听器的行上添加代码行断点 If you think that the event listener gets registered when the page loads, then reload the page. 如果您认为在页面加载时已注册了事件侦听器,请重新加载页面。 The page should stop because of the breakpoint. 该页面应因断点而停止。 The Call Stack pane should help you figure out why the event listener was registered. 呼叫堆栈”窗格应帮助您弄清楚为什么注册了事件侦听器。 Resume script execution and you should see the event listener get registered again. 恢复脚本执行 ,您应该看到事件侦听器再次被注册。 If the event listener doesn't get registered on page load, then just interact with the page in a way that you would expect to create the listener. 如果未在页面加载时注册事件侦听器,则只需以您期望创建侦听器的方式与页面进行交互。

See Get Started With Debugging if you're unfamiliar with stepping through code with DevTools. 如果您不熟悉使用DevTools单步执行代码,请参阅调试入门

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

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