Firebug 不显示我的 javascript?找不到错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11048267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Firebug doesn’t display my javascript? can't find the error
提问by YoniGeek
well I want to debug some script with Firebug, (cause I can't see anything in the browser window) but when I click the script tab in Firefox it gives me the error message:
好吧,我想用 Firebug 调试一些脚本(因为我在浏览器窗口中看不到任何内容)但是当我单击 Firefox 中的脚本选项卡时,它给了我错误消息:
If tags have a "type" attribute, it should equal "text/javascript" or "application/javascript". Also scripts must be parsable (syntactically correct).
如果标签有一个“type”属性,它应该等于“text/javascript”或“application/javascript”。脚本也必须是可解析的(语法正确)。
What am I doing wrong?
我究竟做错了什么?
Here's my code:
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script src="jquery-1.7.1.js"></script>
<script type="text/javascript">
$(function() {
/* fix: “close” the value of i inside createFunction, so it won't change */
var createFunction = function(i) {
return function() { alert(i); };
};
for (var i=0; i<5; i++) {
$('p').appendTo('body').on("click", createFunction(i));
}
})();
</script>
</body>
</html>
采纳答案by acme
You must leave out the last parenthesis, I guess the code should run on dom ready?
你必须省略最后一个括号,我猜代码应该在 dom 上运行就绪?
<script type="text/javascript">
$(function() {
/* fix: “close” the value of i inside createFunction, so it won't change */
var createFunction = function(i) {
return function() { alert(i); };
};
for (var i=0; i<5; i++) {
$('<p>').appendTo('body').on("click", createFunction(i));
}
});
</script>
See herefor how to make code running on dom load with jquery.
请参阅此处了解如何使用 jquery 使代码在 dom 负载上运行。
回答by BJ Patel
In my Case I have opened firebug in other tab, So it was showing me this error.
在我的案例中,我在其他选项卡中打开了 firebug,所以它向我显示了这个错误。
- Solution : I have closed one tab and refreshed the page. and it was working :)
- 解决方案:我关闭了一个选项卡并刷新了页面。它正在工作:)
回答by Engineer
Remove parenthesis after })
:
删除括号后})
:
$(function() {
/* fix: “close” the value of i inside createFunction, so it won't change */
var createFunction = function(i) {
return function() { alert(i); };
};
for (var i=0; i<5; i++) {
$('p').appendTo('body').on("click", createFunction(i));
}
}); //here is the modification