Phpstorm 未解析函数或方法 $()

我有以下问题: phpstorm 不识别 jquery 方法,我看到这里和那里

enter image description here

未解析的函数或方法 $()

这个问题困扰了我一段时间,但最终我试图用 文件-> 设置-> JavaScript-> 库去除它,并将 jquery 添加为一个全局/项目。

我的库设置如下:enter image description here

但是这并没有改变什么。我还能看到那些讨厌的告示。有人知道怎么摆脱他们吗?

57593 次浏览

The jQuery v1.11.0 shows exactly the same behaviour here as well. At the same time previous version 1.10.2 works fine in IDE (no warnings).

I think it has something to do with "AMD-fy jQuery source" ticket (http://bugs.jquery.com/ticket/14113) -- looks like IDE has some issues figuring out this style.

If you wish (and can) -- roll back to jQuery v1.10.2 (which is like half a year old, which means it's stable and still good to use).

Hopefully IDE will be able to properly parse this new jQuery style in next release.


Actual ticket: http://youtrack.jetbrains.com/issue/WEB-10908

If you import both 1.11.0 and 1.10.2 in phpstorm it will be resolved

You don't have to rollback your project.

There is a really stupid workaround,

Download the Library (in this case jQuery) from inside the IDE itself.

  • Open up settings (Ctrl + Alt + S on Linux)
  • Navigate to Languages & Frameworks -> Javascript -> Libraries
  • Click Download and choose jQuery

Hopefully the errors will vanish

Cheers

EDIT: After running the IDE through Fiddler, I realised this only solves the problem because of the version the IDE downloads.

So, the correct workaround is to Add older, non-AMD jQuery versions as a Global scoped Library and add the latest one as a Project scope library.

The latest non-AMD versions are:

1.10.2 for 1.x series. And, 2.0.0 for 2.x series.

I had the same issue with version 1.11.2, and resolved it simply by adding the uncompressed version into my js folder.

Just copy the uncompressed version of jQuery into your project folder. you don't even need to import it into your project, just copy it to javascript folder.