jQuery Intellisense 不适用于 Visual Studio 2012 中的 JavaScript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11488208/
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
Intellisense doesn't work for JavaScript in Visual Studio 2012
提问by Konrad Viltersten
I have a clean, out-of-the-box installation of Visual Studio 2012 Web Developer Express and for some reason the support for JavaScript (both jQuery, jQuery UI and other libraries) has disappeared. I believe it worked before and then for "no reason" it stopped.
我有一个干净的、开箱即用的 Visual Studio 2012 Web Developer Express 安装,由于某种原因,对 JavaScript(jQuery、jQuery UI 和其他库)的支持已经消失。我相信它之前有效,然后“无缘无故”地停止了。
I've browsed the web as supposed to and discovered four discrepancies.
我按预期浏览了网络,发现了四个差异。
I don't have the key HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\JavaScriptLanguageService\ImplicitReferences in my registry. In fact, I don't even have JavaScriptLanguageService directory.
I've checked that the referred file domWindows.js indeed is where the options point to.
The output window under JavaScriptLanguageService is empty and nothing is being typed there while I develop and run my application.
I've referred to the jQuery-file that I'm using through the options but it didn't produce any changes.
我的注册表中没有 HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\JavaScriptLanguageService\ImplicitReferences 键。事实上,我什至没有 JavaScriptLanguageService 目录。
我已经检查过引用的文件 domWindows.js 确实是选项指向的地方。
JavaScriptLanguageService 下的输出窗口是空的,在我开发和运行我的应用程序时没有在那里输入任何内容。
我已经通过选项引用了我正在使用的 jQuery 文件,但它没有产生任何更改。
All in all I get the error message saying that:
总而言之,我收到错误消息说:
"intellisense was unable to determine an accurate completion list for this expression, The provided list contains all identifiers in the file"
“智能感知无法确定此表达式的准确完成列表,提供的列表包含文件中的所有标识符”
Any suggestions would be warmly appreciated.
任何建议将不胜感激。
回答by maxisam
Kudos to CraigTP
感谢CraigTP
Summary:
概括:
navigate to the [Tools] > [Options] > Text Editor > JavaScript > IntelliSense > References options
select Implicit (Web)
you can find "~/Scripts/_references.js" (if you want to put it in different place, change it here)
go to ~/Scripts and add new item "_references.js"
add
/// <reference path="path\jquery-1.7.1.js" />
in "_references.js"or
/// <reference path="~\root\path\jquery-1.7.1.js" />
导航到 [工具] > [选项] > 文本编辑器 > JavaScript > IntelliSense > 参考选项
选择隐式(Web)
你可以找到“~/Scripts/_references.js”(如果你想把它放在不同的地方,在这里改变它)
转到 ~/Scripts 并添加新项目“_references.js”
添加
/// <reference path="path\jquery-1.7.1.js" />
“_references.js”或者
/// <reference path="~\root\path\jquery-1.7.1.js" />
Happy coding :)
快乐编码:)
Edit note:
编辑注释:
Remember to put jquery-1.7.1-vsdoc.js in the same folder with jquery-1.7.1.js
记得把 jquery-1.7.1-vsdoc.js 和 jquery-1.7.1.js 放在同一个文件夹
After making above mentioned changes, if it is still not working try restarting visual studio.
进行上述更改后,如果仍然无法正常工作,请尝试重新启动visual studio。
回答by DRobertE
Go to menu Tools-> Options-> Text Editor-> JavaScript-> Intellisense-> Referencesand place a reference to the intellisense files for the version of jQuery you are using in the Implicit Webgroup.
转到菜单工具->选项->文本编辑器-> JavaScript-> Intellisense->引用,并在隐式 Web组中放置对您正在使用的 jQuery 版本的智能感知文件的引用。
OR
或者
place an "add reference" to the intellisense file in the _references.js file which you can add to the Scripts
folder of your project.
在 _references.js 文件中放置对智能感知文件的“添加引用”,您可以将其添加到Scripts
项目的文件夹中。
/// <reference path="jquery-1.8.2.js"/>
/// <reference path="jquery-1.8.2.min.js"/>
/// <reference path="jquery-1.8.2.intellisense.js"/>
Though this will only provide intellisense for the project you are in, the first will for any open JavaScript file, not just the ones in the project you are in.
虽然这只会为您所在的项目提供智能感知,但第一个将为任何打开的 JavaScript 文件提供智能感知,而不仅仅是您所在项目中的那些。
To get the latest jQuery files with intellisense use the NuGetpackage installer which by default will create a scripts folder and place the jQuery version.js, the min.js and intellisense.js files into... From there you can copy them to the location most of the Microsoft references are placed in, which is typically:
要使用Intellisense获取最新的 jQuery 文件,请使用NuGet包安装程序,默认情况下它将创建一个脚本文件夹并将 jQuery version.js、min.js 和 Intellisense.js 文件放入...从那里您可以将它们复制到大多数 Microsoft 引用都位于的位置,通常是:
install-package jquery
in the package manager console.
install-package jquery
在包管理器控制台中。
C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References
C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References
回答by James
Summary:
概括:
- Drag the
.js
file you want to reference from Solution Explorerinto your current one. (Visual studio will create a reference snippet.)
- 将
.js
要引用的文件从解决方案资源管理器拖到当前的文件中。(Visual Studio 将创建一个参考片段。)
回答by scottheckel
Try adding them to your implicit JavaScript references. This is located at Tools -> Options -> Text Editor -> JavaScript -> IntelliSense -> References.
尝试将它们添加到您的隐式 JavaScript 引用中。它位于工具 -> 选项 -> 文本编辑器 -> JavaScript -> IntelliSense -> 参考。
回答by netfed
To add jQuery and its intellisense files to an active/opened project/website
将 jQuery 及其智能感知文件添加到活动/打开的项目/网站
In Visual Studio 2012, do the following:
在 Visual Studio 2012 中,执行以下操作:
Open menu Tools-> Library Packet Manager-> Manage Nuget packages for solution. Click the Online field/selector in the very right side of the dialog box. Find jQuery in the middle list, click it, and click Install.
打开菜单Tools-> Library Packet Manager-> Manage Nuget packages for solution。单击对话框最右侧的在线字段/选择器。在中间列表中找到 jQuery,单击它,然后单击Install。
Observe that the jQuery script files are now inserted into your project by looking at the Solution Explorer panel. You should see jquery-1.x.x.js (where x here is are placeholders for the actual version numbers. Say jquery-1.9.0.js is a concrete example).
通过查看解决方案资源管理器面板,可以观察到 jQuery 脚本文件现在已插入到您的项目中。你应该看到 jquery-1.xxjs (这里的 x 是实际版本号的占位符。说 jquery-1.9.0.js 是一个具体的例子)。
Also, observe that there is now a Jquery-1.9.0.intellisense.js file there. Neat ai? :-)
另外,请注意现在那里有一个 Jquery-1.9.0.intellisense.js 文件。整洁的艾?:-)
But bear in mind, that if you create a new website in Visual Studio and choose ASP:NET Web forms site (as opposed to an Empty site) the web forms site will already have jQuery 1.7.1 in there).
但请记住,如果您在 Visual Studio 中创建一个新网站并选择 ASP:NET Web 表单站点(而不是空站点),则 Web 表单站点中已经包含 jQuery 1.7.1)。
回答by Trio Cheung
I included jquery-xxx.intellisense.js in JavaScript-> Intellisense-> Reference. It worked one time, but after I closed Visual Studio and restarted it, intellisense didn't work again. But I accidentally hit menu Edit -> intellisense-> Refresh Remote References. It worked again. Try that!
我在JavaScript-> Intellisense-> Reference 中包含了 jquery-xxx.intellisense.js 。它工作过一次,但在我关闭 Visual Studio 并重新启动它后,智能感知不再工作。但我不小心点击了菜单 Edit -> Intellisense-> Refresh Remote References。它又奏效了。试试吧!
回答by Ashraf Abusada
Use NuGet IntelliSense documentation package for JQuery by installing it like this from the NuGet console:
通过从 NuGet 控制台像这样安装,将 NuGet IntelliSense 文档包用于 JQuery:
Install-Package jQuery-vsdoc
Install-Package jQuery-vsdoc
After you install the package go to:
安装软件包后转到:
Tools>>Options>>Text Editor>>JavaScript>>Intellisense>>References
Tools>>Options>>Text Editor>>JavaScript>>Intellisense>>References
and Add reference to Implicit(Web)
group by selecting the installed package location on your hard drive.
并Implicit(Web)
通过选择硬盘驱动器上的安装包位置来添加对组的引用。
restart Visual Studio, and you will get the jQuery intellisense working.
重新启动 Visual Studio,您将获得 jQuery 智能感知工作。
回答by Noah Stahl
What ended up working for me was to reorder the list in _references.js. I had almost 150 lines in there due to a bunch of plugins imported into the project, and jQuery was near the bottom. When I moved its reference to the top, my intellisense started working again.
最终对我有用的是重新排序 _references.js 中的列表。由于项目中导入了一堆插件,我在那里有将近 150 行代码,而 jQuery 接近底部。当我将它的引用移到顶部时,我的智能感知又开始工作了。
What it looks like:
它的样子:
/// <autosync enabled="true" />
/// <reference path="jquery-2.1.3.js" />
/// <reference path="jquery-ui-1.11.2.js" />
/// <reference path="modernizr-2.8.3.js" />
... more reference lines
Note the reference is to the jquery-{version}.js file. There is also a file installed with the Nuget package in the same directory named jquery-{version}.intelliense.js, which I assume is what is used. Hope that helps.
请注意,引用是对 jquery-{version}.js 文件的引用。还有一个与 Nuget 包一起安装在名为 jquery-{version}.intelliense.js 的同一目录中的文件,我假设它是使用的。希望有帮助。