有一个page1.html(我用浏览器打开):
<div id="content">
</div>
<script type="text/JavaScript">
jQuery.ajax({
type : "GET",
url : 'page2.html',
dataType : "html",
success : function(response) {
jQuery('#content').append(response);
}
});
</script>
page2.html的代码:
<script type="text/JavaScript" src="js/page2.js"></script>
<script type="text/JavaScript">
test();
</script>
页面js/page2.js代码:
function test() {
alert('Function Test()');
}
一切正常,显示“Function Test()”窗口。但问题是我无法在 firebug js 调试器中访问函数 test() 的代码。它既不会出现在事件脚本中,也不会出现在 eval 中。
我该如何解决?
仅供引用: 如果我不将函数放在单独的 js 文件中,而是将它放在 page2.html 中,它 正确出现在调试器中。
如果我在 test() 函数中加入“调试器”这个词,Firebug 会停止,但函数的源代码仍然无法访问。
版本:Firefox 3.0.10、Firebug 1.3.3
更新:与问题 Making Firebug break inside dynamically loaded javascript 几乎相同, 但还没有答案
最佳答案
这是一个 hack,但我通过两次添加 debugger 这个词让 Firebug 停止在外部文件 js/page2.js
中。一次在文件的顶部,另一次在函数的顶部。
如果调试器字在任何一个地方都只有一次,firebug 不会停止。
debugger;
function test() {
debugger;
alert('Function Test()');
}
关于javascript - 动态加载的 js 函数不会出现在 Firebug js 调试器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/874256/