我在想如何将jquery导入到.js文件。我希望能够使用代码提示(intellinse),但鉴于这是一个单独的文件,我不能这样做。也许我不需要导入,但有什么办法可以得到获取代码提示以便为外部JavaScript文件(.js)工作
$().[hint]
要在独立的.js文件中出现吗?
我在想如何将jquery导入到.js文件。我希望能够使用代码提示(intellinse),但鉴于这是一个单独的文件,我不能这样做。也许我不需要导入,但有什么办法可以得到获取代码提示以便为外部JavaScript文件(.js)工作
$().[hint]
要在独立的.js文件中出现吗?
在你的js的开始把这个文件
/// <reference path="/js/jquery.js" />
在我的IDE版本(NetBeans)
非常感谢,奇妙的作品! – 2012-07-30 05:11:50
您可以将其从“解决方案资源管理器”拖到您的js文件中进行添加。 – Charlie 2012-07-30 05:12:39
这必须在评论中,对吧? – AdityaParab 2012-07-30 05:13:16
下面是微软的智能感知页面的JavaScript:http://msdn.microsoft.com/en-us/library/bb385682.aspx
我用自己的格式和它的作品普遍好评。 jQuery有一个导出(jquery- [版本] -vsdoc.js或类似的东西),你放在脚本目录中。
然后,您在脚本的顶部添加///<reference path="path/to/jquery-[version].js" />
,并且所有内容似乎都可以工作(对于大多数情况)。
有在架构非常有限的文档,但我已经创建什么样的架构看起来像一个粗略的XSD(VS不拿起所有他们声称,虽然支持的东西)
编辑:如果安装了SP1对于VS2010,您应该获得JS智能感知的最新支持。如果没有,微软有一个支持它的扩展。为了获得上述-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智能感知支持标签写一个例子:
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;
}
,这个工作外的开箱 – 2012-07-30 04:49:30
我使用Visual Studio的不幸(虽然我不得不说,我宁愿使用NetBeans,但我不能:() – 2012-07-30 04:49:48
我使用DW CS6,它有本地jQuery自动完成。大多数情况下,我更喜欢在没有任何codehinting的情况下编写代码,但我的创造力最适合IMO这种方式。 – 2012-07-30 04:52:23