获取用于外部JavaScript文件(.js)的代码提示
我想知道如何将jquery导入到.js文件中。我希望能够使用代码提示(intellinse),但鉴于这是一个单独的文件,我不能这样做。也许我不需要进口,但有没有办法获取用于外部JavaScript文件(.js)的代码提示,javascript,jquery,visual-studio,Javascript,Jquery,Visual Studio,我想知道如何将jquery导入到.js文件中。我希望能够使用代码提示(intellinse),但鉴于这是一个单独的文件,我不能这样做。也许我不需要进口,但有没有办法 $().[hint] 要在独立的.js文件中显示?以下是microsoft关于intellisense for javascript的页面: 我使用了他们的格式,它通常工作得很好。jQuery有一个导出(jQuery-[version]-vsdoc.js或类似的东西),您可以将它放在脚本目录中 然后在脚本的顶部添加//,一切看起来
$().[hint]
要在独立的.js文件中显示?以下是microsoft关于intellisense for javascript的页面: 我使用了他们的格式,它通常工作得很好。jQuery有一个导出(jQuery-[version]-vsdoc.js或类似的东西),您可以将它放在脚本目录中 然后在脚本的顶部添加
//
,一切看起来都正常(对于大多数情况)
关于这个模式的文档非常有限,但我已经创建了一个粗略的XSD来描述这个模式的样子(不过VS并没有收集到他们声称支持的所有东西)
编辑:如果您为VS2010安装SP1,您应该获得对JS intellisense的最新支持。如果没有,微软有一个扩展来支持它。要获取上面提到的-vsdoc.js文件,最简单的方法是通过nuget获取它
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Schema is based on http://weblogs.asp.net/bleroy/archive/2007/04/23/the-format-for-javascript-doc-comments.aspx -->
<!-- para tags are not specced on that page but are included as part of the VS JScript Editor Extensions -->
<!-- The "End" tag is a wrapper tag so I can make a valid document -->
<xs:element name="End">
<xs:complexType>
<xs:choice>
<xs:element name="reference" minOccurs="0" maxOccurs="unbounded" type="referenceType"/>
<xs:sequence>
<xs:element name="summary" type="TextContent"/>
<xs:element name="param" minOccurs="0" maxOccurs="unbounded" type="ParamNamedTypedTextContent" />
<xs:element name="field" minOccurs="0" maxOccurs="unbounded" type="NamedTypedTextContent" />
<xs:element name="returns" minOccurs="0" maxOccurs="1" type="TypedTextContent" />
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="referenceType">
<xs:attribute name="path" type="xs:string" use="required" />
<xs:attribute name="assembly" type="xs:string" use="optional" />
<xs:attribute name="name" type="xs:string" use="optional" />
</xs:complexType>
<xs:complexType name="TextContent" mixed="true">
<xs:sequence>
<xs:element name="para" minOccurs="0" maxOccurs="unbounded" type="xs:string" />
</xs:sequence>
<xs:attribute name="locid" type="xs:string" use="optional" />
</xs:complexType>
<xs:complexType name="TypedTextContent">
<xs:complexContent>
<xs:extension base="TextContent">
<xs:attribute name="type" type="xs:string" use="optional" />
<xs:attribute name="elementType" type="xs:string" use="optional" />
<xs:attribute name="integer" type="xs:boolean" use="optional" />
<xs:attribute name="mayBeNull" type="xs:boolean" use="optional" />
<xs:attribute name="domElement" type="xs:boolean" use="optional" />
<xs:attribute name="elementInteger" type="xs:boolean" use="optional" />
<xs:attribute name="elementDomElement" type="xs:boolean" use="optional" />
<xs:attribute name="elementMayBeNull" type="xs:boolean" use="optional" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="NamedTypedTextContent">
<xs:complexContent>
<xs:extension base="TypedTextContent">
<xs:attribute name="name" type="xs:string" use="required" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="ParamNamedTypedTextContent">
<xs:complexContent>
<xs:extension base="NamedTypedTextContent">
<xs:attribute name="optional" type="xs:boolean" use="optional" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
编辑2:
下面是我使用VS intellisense支持的标记编写的一些代码的示例:
function getDottedProperty(obj, dottedPropertyChain) {
///<summary>
/// <para>
/// Returns the property of the object given by the dotted property
/// chain.
/// </para>
/// <para>
/// Example:
/// GetDottedProperty(
/// { a: { b: { c: { d: 'hello' } } } },
/// 'a.b.c.d'
/// )
/// </para>
///</summary>
///<param name="obj" type="Object">Object</param>
///<param name="dottedPropertyChain" type="String">
/// The string of properties to access.
///</param>
var propertySplits = dottedPropertyChain.split('.');
while (propertySplits.length) {
obj = obj[propertySplits.shift()];
}
return obj;
}
函数getDottedProperty(obj,dottedPropertyChain){
///
///
///返回虚线属性给定的对象的属性
///链子。
///
///
///例如:
///GetDottedProperty(
///{a:{b:{c:{d:'hello'}}},
///“a.b.c.d”
/// )
///
///
///反对
///
///要访问的属性字符串。
///
var-propertySplits=dottedPropertyChain.split('.');
while(propertySplits.length){
obj=obj[propertySplits.shift()];
}
返回obj;
}
将其放在js文件的开头
/// <reference path="/js/jquery.js" />
//
在我的IDE(netbeans)中,这是一种开箱即用的方式。不幸的是,我正在使用Visual Studio(尽管我不得不说我更愿意使用netbeans,但我不能:()我使用DW CS6,它有本机jQuery自动完成功能。大多数时候,我更喜欢在没有任何代码提示的情况下编写代码,但我的创造力在我看来最适合这种方式。你可以通过将它从“解决方案资源管理器”拖到js文件来添加它。我从google资源中获取jQuery,但如果我添加它,它会工作得非常出色///