我想知道如何将jquery导入到.js文件中。我希望能够使用codehints(intellinse),但鉴于这是一个单独的文件,我不能这样做。也许我不需要导入,但有没有办法获得
$().[hint]
显示在独立的.js文件中?
答案 0 :(得分:6)
将它放在你的js文件的开头
/// <reference path="/js/jquery.js" />
答案 1 :(得分:0)
这是关于javascript的intellisense的微软页面:http://msdn.microsoft.com/en-us/library/bb385682.aspx
我使用过它们的格式,效果一般。 jQuery有一个导出(jquery- [version] -vsdoc.js或类似的东西)放在你的Scripts目录中。
然后在脚本的顶部添加///<reference path="path/to/jquery-[version].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>
EDIT2: 以下是使用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;
}