如何在Visual Studio 2008中获得JavaScript/jQuery智能感知功能?

时间:2022-11-14 08:11:46

I thought jQuery Intellisense was supposed to be improved with SP1. I even downloaded an annotated version of jQuery 1.2.6, but intellisense will not work in a separate jscript file. I have the jQuery library referenced first on my web page in the <head> tag. Am I doing anything wrong?

我认为jQuery Intellisense应该用SP1来改进。我甚至下载了一个注释版的jQuery 1.2.6,但是智能感知不会在单独的jscript文件中工作。我的web页面上的jQuery库首先在标记中被引用。我做错什么了吗?

9 个解决方案

#1


87  

At the top of your external JavaScript file, add the following:

在您的外部JavaScript文件的顶部,添加以下内容:

/// <reference path="jQuery.js"/>

Make sure the path is correct, relative to the file's position in the folder structure, etc.

确保路径是正确的,相对于文件在文件夹结构中的位置,等等。

Also, any references need to be at the top of the file, before any other text, including comments - literally, the very first thing in the file. Hopefully future version of Visual Studio will work regardless of where it is in the file, or maybe they will do something altogether different...

此外,任何引用都必须在文件的顶部,在任何其他文本(包括注释)之前,也就是文件中的第一件事。希望未来的Visual Studio版本不管它在文件中的什么位置都能工作,或者他们可能会做一些完全不同的事情……

Once you have done that and saved the file, hit Ctrl + Shift + J to force Visual Studio to update Intellisense.

完成该操作并保存文件之后,按Ctrl + Shift + J来强制Visual Studio更新Intellisense。

#2


15  

There is an officially supported jQuery documentation JavaScript file for Visual Studio 2008. This file is only an interim fix until Microsoft releases a hotfix that will more adequately address the issue.

Visual Studio 2008有一个官方支持的jQuery文档JavaScript文件。在微软发布一个能够更充分地解决这个问题的热修复之前,这个文件只是一个临时修复。

Embedded in ASPX:

嵌入在ASPX:

<% if (false) { %>
    <script src="jquery-1.2.6-vsdoc.js" type="text/javascript"></script>
<% } %>

Embedded in JavaScript:

嵌入JavaScript:

/// <reference path="jquery-1.2.6-vsdoc.js" />

Pick it up here: jquery-1.2.6-vsdoc.js

在这里选择:jquery-1.2.6-vsdoc.js

References:

引用:

#3


8  

You'll want to look at this link:

你会想看看这个链接:

http://blogs.ipona.com/james/archive/2008/02/15/JQuery-IntelliSense-in-Visual-Studio-2008.aspx

http://blogs.ipona.com/james/archive/2008/02/15/jquery——智能感知- 2008. aspx -视觉工作室

UPDATE: There is a new HotFix for Visual Studio 2008 and a new jQuery Intellisense Documentation file that brings full jQuery Intellisense to VS'08. Below are links to get these two:

更新:Visual Studio 2008有一个新的HotFix和一个新的jQuery Intellisense文档文件,它将完整的jQuery Intellisense带到VS'08。下面是获得这两个的链接:

http://blogs.msdn.com/webdevtools/archive/2008/11/07/hotfix-to-enable-vsdoc-js-intellisense-doc-files-is-now-available.aspx

http://blogs.msdn.com/webdevtools/archive/2008/11/07/hotfix-to-enable-vsdoc-js-intellisense-doc-files-is-now-available.aspx

http://blogs.msdn.com/webdevtools/archive/2008/10/28/rich-intellisense-for-jquery.aspx

http://blogs.msdn.com/webdevtools/archive/2008/10/28/rich-intellisense-for-jquery.aspx

#4


3  

For inline JavaScript, use:

对于内联JavaScript,使用:

/// <reference path="~\js\jquery-vsdoc.js"/>

/ / / <参考路径= " ~ \ js jquery-vsdoc.js>

Note the back slashes.

注意,反斜杠。

This will not work:

这将不工作:

/// <reference path="~/js/jquery-vsdoc.js"/>

/ / / <参考路径= " ~ js jquery-vsdoc.js>

#5


2  

You shouldn't need to actually reference the "-vsdoc" version. If you put the jquery-1.2.6-vsdoc.js in the same directory as jquery-1.2.6.js then Visual Studio will know to covert a jquery-1.2.6.js reference to jquery-1.2.6-vsdoc.js.

您不需要实际引用“-vsdoc”版本。如果你放入jquery-1.2.6-vsdoc。在与jquery-1.2.6相同的目录中。然后Visual Studio就会知道如何隐藏jquery-1.2.6。jquery-1.2.6-vsdoc.js js引用。

I think that will actually work for any file.

我认为这对任何文件都适用。

Hmmm... that gives a good workaround for another question on this site...

嗯…这为这个网站上的另一个问题提供了一个很好的解决方案。

Edit: This feature only works with VS2008 Service Pack 1.

编辑:此功能只适用于VS2008服务包1。

#6


2  

If you are including the annotated jQuery file in your source solely for intellisense, I recommend leveraging preprocessor directives to remove it from your view when you compile. Ala:

如果您在源代码中仅为智能感知包含注释jQuery文件,那么我建议您利用预处理器指令在编译时从您的视图中删除它。阿拉巴马州:

<% #if (false) %>
  <!-- This block is here for jquery intellisense only.  It will be removed by the compiler! -->
  <script type="text/javascript" src="Scripts/jquery-1.3.2-vsdoc.js"></script>
<% #endif %>

Then later in your code you can really reference jQuery. This is handy when using the Google AJAX Libraries API, because you get all the benefits Google provides you, plus intellisense.

然后,在代码中,您可以真正引用jQuery。这在使用谷歌AJAX库API时非常方便,因为您可以获得谷歌提供的所有好处,还有智能感知。

Here is a sample of using the Libraries API:

下面是使用库API的示例:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
   google.load("jquery", "1.3.2", { uncompressed: false });
</script>

#7


0  

jQuery Intellisense in Visual Studio 2008

Visual Studio 2008中的jQuery Intellisense

#8


0  

If you want to pick up the Intellisense file from the Microsoft CDN you can use:

如果您想从Microsoft CDN中获取Intellisense文件,您可以使用:

/// <reference path="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1-vsdoc.js" />

#9


0  

Make sure you're not using a minimized jQuery file.

确保您没有使用最小化的jQuery文件。

Use Ctrl + Shift + J to make it work after adding JavaScript files to the project.

在向项目中添加JavaScript文件之后,使用Ctrl + Shift + J使其工作。

#1


87  

At the top of your external JavaScript file, add the following:

在您的外部JavaScript文件的顶部,添加以下内容:

/// <reference path="jQuery.js"/>

Make sure the path is correct, relative to the file's position in the folder structure, etc.

确保路径是正确的,相对于文件在文件夹结构中的位置,等等。

Also, any references need to be at the top of the file, before any other text, including comments - literally, the very first thing in the file. Hopefully future version of Visual Studio will work regardless of where it is in the file, or maybe they will do something altogether different...

此外,任何引用都必须在文件的顶部,在任何其他文本(包括注释)之前,也就是文件中的第一件事。希望未来的Visual Studio版本不管它在文件中的什么位置都能工作,或者他们可能会做一些完全不同的事情……

Once you have done that and saved the file, hit Ctrl + Shift + J to force Visual Studio to update Intellisense.

完成该操作并保存文件之后,按Ctrl + Shift + J来强制Visual Studio更新Intellisense。

#2


15  

There is an officially supported jQuery documentation JavaScript file for Visual Studio 2008. This file is only an interim fix until Microsoft releases a hotfix that will more adequately address the issue.

Visual Studio 2008有一个官方支持的jQuery文档JavaScript文件。在微软发布一个能够更充分地解决这个问题的热修复之前,这个文件只是一个临时修复。

Embedded in ASPX:

嵌入在ASPX:

<% if (false) { %>
    <script src="jquery-1.2.6-vsdoc.js" type="text/javascript"></script>
<% } %>

Embedded in JavaScript:

嵌入JavaScript:

/// <reference path="jquery-1.2.6-vsdoc.js" />

Pick it up here: jquery-1.2.6-vsdoc.js

在这里选择:jquery-1.2.6-vsdoc.js

References:

引用:

#3


8  

You'll want to look at this link:

你会想看看这个链接:

http://blogs.ipona.com/james/archive/2008/02/15/JQuery-IntelliSense-in-Visual-Studio-2008.aspx

http://blogs.ipona.com/james/archive/2008/02/15/jquery——智能感知- 2008. aspx -视觉工作室

UPDATE: There is a new HotFix for Visual Studio 2008 and a new jQuery Intellisense Documentation file that brings full jQuery Intellisense to VS'08. Below are links to get these two:

更新:Visual Studio 2008有一个新的HotFix和一个新的jQuery Intellisense文档文件,它将完整的jQuery Intellisense带到VS'08。下面是获得这两个的链接:

http://blogs.msdn.com/webdevtools/archive/2008/11/07/hotfix-to-enable-vsdoc-js-intellisense-doc-files-is-now-available.aspx

http://blogs.msdn.com/webdevtools/archive/2008/11/07/hotfix-to-enable-vsdoc-js-intellisense-doc-files-is-now-available.aspx

http://blogs.msdn.com/webdevtools/archive/2008/10/28/rich-intellisense-for-jquery.aspx

http://blogs.msdn.com/webdevtools/archive/2008/10/28/rich-intellisense-for-jquery.aspx

#4


3  

For inline JavaScript, use:

对于内联JavaScript,使用:

/// <reference path="~\js\jquery-vsdoc.js"/>

/ / / <参考路径= " ~ \ js jquery-vsdoc.js>

Note the back slashes.

注意,反斜杠。

This will not work:

这将不工作:

/// <reference path="~/js/jquery-vsdoc.js"/>

/ / / <参考路径= " ~ js jquery-vsdoc.js>

#5


2  

You shouldn't need to actually reference the "-vsdoc" version. If you put the jquery-1.2.6-vsdoc.js in the same directory as jquery-1.2.6.js then Visual Studio will know to covert a jquery-1.2.6.js reference to jquery-1.2.6-vsdoc.js.

您不需要实际引用“-vsdoc”版本。如果你放入jquery-1.2.6-vsdoc。在与jquery-1.2.6相同的目录中。然后Visual Studio就会知道如何隐藏jquery-1.2.6。jquery-1.2.6-vsdoc.js js引用。

I think that will actually work for any file.

我认为这对任何文件都适用。

Hmmm... that gives a good workaround for another question on this site...

嗯…这为这个网站上的另一个问题提供了一个很好的解决方案。

Edit: This feature only works with VS2008 Service Pack 1.

编辑:此功能只适用于VS2008服务包1。

#6


2  

If you are including the annotated jQuery file in your source solely for intellisense, I recommend leveraging preprocessor directives to remove it from your view when you compile. Ala:

如果您在源代码中仅为智能感知包含注释jQuery文件,那么我建议您利用预处理器指令在编译时从您的视图中删除它。阿拉巴马州:

<% #if (false) %>
  <!-- This block is here for jquery intellisense only.  It will be removed by the compiler! -->
  <script type="text/javascript" src="Scripts/jquery-1.3.2-vsdoc.js"></script>
<% #endif %>

Then later in your code you can really reference jQuery. This is handy when using the Google AJAX Libraries API, because you get all the benefits Google provides you, plus intellisense.

然后,在代码中,您可以真正引用jQuery。这在使用谷歌AJAX库API时非常方便,因为您可以获得谷歌提供的所有好处,还有智能感知。

Here is a sample of using the Libraries API:

下面是使用库API的示例:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
   google.load("jquery", "1.3.2", { uncompressed: false });
</script>

#7


0  

jQuery Intellisense in Visual Studio 2008

Visual Studio 2008中的jQuery Intellisense

#8


0  

If you want to pick up the Intellisense file from the Microsoft CDN you can use:

如果您想从Microsoft CDN中获取Intellisense文件,您可以使用:

/// <reference path="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1-vsdoc.js" />

#9


0  

Make sure you're not using a minimized jQuery file.

确保您没有使用最小化的jQuery文件。

Use Ctrl + Shift + J to make it work after adding JavaScript files to the project.

在向项目中添加JavaScript文件之后,使用Ctrl + Shift + J使其工作。