English 中文(简体)
JSHint and jQuery:$ is not defined
原标题:JSHint and jQuery: $ is not defined

The following JS:

(function() {
  "use strict";

  $("#target").click(function(){
    console.log("clicked");
  });

}());

继承:

test.js: line 5, col 3,  $  is not defined.

当使用JHint0.5.5时。 任何想法?

最佳回答

如果你使用比较近期的JHint版本,通常更可取的做法是在你的项目根基中建立一个jshintrc文档,并将这一简略列入:

{
    "globals": {
        "$": false
    }
}

这向人权联盟宣布,美元是一个全球性的变数,而错误表明,它不应凌驾于一切之上。

最初的Jshintrc案(例如,与2012年原始问题一样)没有得到支持。 如果你不能或不想使用jshintrc文档,你可以在文件顶上添加:

/*globals $:false */

上,还有一段简短的“jquery” j。 JSHint Options page .

问题回答

你还可以在你看来增加两条。

  "globals": {
    "$": false,
    "jQuery": false
  }

这说明有两种全球变量。

页: 1

http://www.jshint.com/docs/options/#jquery。 JSHint Options reference:

jquery

这一办法界定了Jan Query Java成文图书馆所揭露的全球人物。

Here is a happy little list to put in your .jshintrc
I will add to this list at time passes.

{
  // other settings...
  // ENVIRONMENTS
  // "browser": true, // Is in most configs by default
  "node": true,
  // others (e.g. yui, mootools, rhino, worker, etc.)
  "globals": {
    "$":false,
    "jquery":false,
    "angular":false
    // other explicit global names to exclude
  },
}

如果您重新使用英特尔利J编辑,如WebStorm、PyCharm、Ruby Mine或IntelliJ IDEA:

In the Environments section of File/Settings/JavaScript/Code Quality Tools/JSHint, click on the jQuery checkbox.

如果你重新使用英特尔利J编辑,主编

  • Preferences/Settings
    • Javascript
      • Code Quality Tools
        • JSHint
          • Predefined (at bottom), click Set

你可以做任何事情,例如<代码>console:false,并将在清单(jshintrc)中加上全球。

您也许想做以下工作:

const $ = window.$

避免出现倾斜错误。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签