是否可以使用JSLint验证我的jQuery JavaScript? [英] Is it possible to validate my jQuery JavaScript with JSLint?

查看:68
本文介绍了是否可以使用JSLint验证我的jQuery JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用JSLint检查我的JavaScript。我也在使用jQuery,JSLint似乎对jQuery非常不满。

I wanted to check my JavaScript with JSLint. I am also using jQuery and JSLint seems to be very unhappy about jQuery.

所以,如果我有这个代码:

So, if I have this code:

$(document).ready{
    $("a").click(function() {
        // foo
    });
});

我收到一些JSLint消息:

I am getting a few JSLint messages:

错误:

第1行问题1:在定义之前使用了'$'。

Problem at line 1 character 1: '$' was used before it was defined.

$(document).ready{

...

我查看了这些选项,但我无法弄清楚如何告诉JSLint这没关系。

I had a look at the options but I couldn't figure out how to tell JSLint that this is ok.

如果我的代码中只有一个jQuery调用,我可以忽略JSLint消息但是在2,500行脚本中有很多对于调用,我无法找到我想在所有这些消息之间修复的错误。

If I had only one jQuery call in my code I could just ignore the JSLint message but in 2,500 lines of script there are lots of calls, I can't find the errors I'd like to fix between all these messages.

那么,有没有人知道如何配置JSLint使其适用于jQuery调用?或者还有什么我可以用来检查我的JavaScript / jQuery代码的质量?

So, does anyone know how to configure JSLint such that it works with jQuery calls? Or is there something else I can use to check the quality of my JavaScript/jQuery code?

推荐答案

这是无效的JavaScript,它应该是:

That's not valid JavaScript, it should be:

$(document).ready(function() {

所以JSLint会(适当地)抱怨你的语法。

So JSLint will (appropriately) complain about your syntax.

如果你想摆脱暗示全局:$,document 消息,在预定义(,分隔)的底部,并放入在该文本框中的jQuery,$ 然后再次运行。对于文档,请在第一列中选​​中假设浏览器

If you want to get rid of the Implied global: $, document message, go to the bottom where it has Predefined (, separated), and put jQuery, $ in that textbox then run again. For the document piece, check Assume a browser in the first column.

所有JSLint设置都会坚持下去,所以每次回去都不需要这样做。

All JSLint settings will stick, so you don't have to do this each time you go back.

这篇关于是否可以使用JSLint验证我的jQuery JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆