如何查找jquery或javascript事件从哪个文件发生


How to find jquery or javascript event occure from which file?

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/file1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/file2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/file3.js"></script>
<script type="text/javascript" src="http://code.jquery.com/file4.js"></script><script type="text/javascript" src="http://code.jquery.com/file5.js"></script>

我有 100 个或更多 JS 文件警报消息来自任何地方,如何隐藏和查找?

我认为没有直接的方法。一种可能的方法是使用检查工具或任何事件可视化插件。

在您的情况下,您可以在警报消息上使用当前页面名称来标识页面。

    var script_name = document.getElementsByTagName("script")[0].src;
    alert( 'alert message from the file ' + script_name );

但我不认为这是一个好方法。我建议使用视觉事件等工具

http://www.sprymedia.co.uk/article/Visual+Event+2

谷歌浏览器插件也可用

http://tinyurl.com/a5hcod2

假设你有这个

文件 1:

         $(element).bind("click", function(){
              console.dir('button in some file', this);
         });

文件 2 :

           $(element).bind("click", function(){
                console.dir('button in another file', this);
           });

如果您单击并检查控制台,您应该有这样的东西

button in some file html elememt .... file1.js:15
button in another file html elememt .... file2.js:20