javascript JSLint 警告“文档”未在 jQuery(document).ready 上完全定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7090642/
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
JSLint warns that "document" is not fully defined on jQuery(document).ready
提问by Ben
I get a
我得到一个
'document' has not been fully defined yet.
$(document).ready(function () {
warning from jsLint
.
I get why this happends but I would like my code to be warning free.
来自 的警告jsLint
。我明白为什么会发生这种情况,但我希望我的代码没有警告。
My question is - how do I either solve this in code (assign document to itself? var document=document
?) or maybe make the warning go away some other way.
我的问题是 - 我如何在代码中解决这个问题(将文档分配给自己var document=document
??)或者让警告以其他方式消失。
Thanks.
谢谢。
采纳答案by Emil Ivanov
I think you can safely ignore that. If you don't want it to show anyway, rewrite it like so
我认为你可以放心地忽略它。如果你不想它显示无论如何,像这样重写它
$(function () {
// Document is ready
});
$(function () {})
and $(document).ready(function () {})
are equivalent.
$(function () {})
并且$(document).ready(function () {})
是等价的。
回答by Jayantha Lal Sirisena
You can simply use
你可以简单地使用
/*jslint browser:true */
in the beginning of the code to assume a browser.
在代码的开头假设一个浏览器。
回答by Andrew Duffy
Use the shorthand:
使用简写:
$(function() {
...
});
回答by Mikhail
If you prefer to keep your code the way you have it, you can tell JSlint to be OK with your decision:
如果你更喜欢保留你的代码,你可以告诉 JSlint 接受你的决定:
/*global document*/
$(document).ready(function () {
...
}
This indicates that document
has been defined elsewhere.
这表明document
已在别处定义。
回答by user2613758
JSLint requires that you assume a browser in the selector options. the document will be defined then. Using $ will not help here...not in JSLint anyway.
JSLint 要求您在选择器选项中使用浏览器。然后将定义该文档。在这里使用 $ 无济于事……无论如何在 JSLint 中都没有。
回答by equiman
create an .jsintrc on root folder, with this:
在根文件夹上创建一个 .jsintrc ,如下:
{
"browser": true
}
{
"browser": true
}
You can see all options in JSHint Options
您可以在JSHint Options 中看到所有选项