简体   繁体   English

有没有一种简单的方法来查找阻止事件默认值的代码?

[英]is there an easy way to find code that is preventing event default?

This issue has come up for me a few times: 这个问题对我来说已经好几次了:

I write some code that handles an event, for example a click. 我编写了一些处理事件的代码,例如单击。 I click the element and nothing happens. 我单击该元素,没有任何反应。 Some other code is calling e.preventDefault() before my code has the chance to handle it. 在我的代码有机会处理它之前,其他一些代码正在调用e.preventDefault()

Question: 题:
Is there a way to find the code that is preventing default that i have overlooked? 有没有办法找到防止我忽视的默认代码?

I usually solve this by running javascript profiler in firebug and looking at every function that is called during the click (not inside jquery etc) that may be doing the evil. 我通常通过在Firebug中运行javascript profiler并查看可能在做恶的单击(而不是在jquery等内部)中调用的每个函数来解决此问题。 There has to be a better way. 一定有更好的方法。

I would put a test alert in the function that is supposed to execute, starting at the top and then moving it downwards after each statement. 我将在应该执行的函数中放置一个测试警报,该警报从顶部开始,然后在每个语句之后向下移动。 If the alert doesn't execute at the top of the function I would check your HTML element and how you are selecting it. 如果警报没有在函数顶部执行,我将检查您的HTML元素以及如何选择它。 If everything appears to be good, I would search your files using possible element selectors. 如果一切似乎都很好,我将使用可能的元素选择器搜索您的文件。

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

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