Jquery 和 Jslint - '$' 在定义之前就被使用了
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18251388/
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
Jquery and Jslint - '$' was used before it was defined
提问by user1555190
I have some third party javascript im working with, I added some jquery code into it the javascript file. But it seems to fail on the above code when validating using Jslint
我有一些第三方 javascript 正在使用,我在 javascript 文件中添加了一些 jquery 代码。但是在使用 Jslint 进行验证时,上面的代码似乎失败了
'$' was used before it was defined.
I can see at the top of the javascript file it states:
我可以在 javascript 文件的顶部看到它指出:
/*global alert: false, console: false, jQuery: false */
Im relatively new to Javascript, and JQuery, so any help would be welcome.
我对 Javascript 和 JQuery 比较陌生,因此欢迎提供任何帮助。
回答by kernel
Add these options to your comments:
将这些选项添加到您的评论中:
/*jslint browser: true*/
/*global $, jQuery, alert*/
回答by Quentin
If you want to use variables provided by other scripts, then you need to say so:
如果你想使用其他脚本提供的变量,那么你需要这样说:
/*global $ */
回答by Zon
For JSLint In NetbeansIDE go to:
对于NetbeansIDE 中的JSLint,请转到:
Tools
- Options
- Miscellaneous
- JSLint tab
- Text area
under "Predefined (, separated)":
Tools
- Options
- Miscellaneous
- JSLint tab
-Text area
在“预定义(,分隔)”下:
- add $;
- add your other project global variables, separating with comma.
- 添加 $;
- 添加您的其他项目全局变量,用逗号分隔。
Now JQuery variable $ is considered defined everywhere in code.
现在 JQuery 变量 $ 被认为是定义在代码中的任何地方。