2012-07-30 44 views
2

我在想如何將jquery導入到.js文件。我希望能夠使用代碼提示(intellinse),但鑑於這是一個單獨的文件,我不能這樣做。也許我不需要導入,但有什麼辦法可以得到獲取代碼提示以便爲外部JavaScript文件(.js)工作

$().[hint] 

要在獨立的.js文件中出現嗎?

+0

,這個工作外的開箱 – 2012-07-30 04:49:30

+0

我使用Visual Studio的不幸(雖然我不得不說,我寧願使用NetBeans,但我不能:() – 2012-07-30 04:49:48

+1

我使用DW CS6,它有本地jQuery自動完成。大多數情況下,我更喜歡在沒有任何codehinting的情況下編寫代碼,但我的創造力最適合IMO這種方式。 – 2012-07-30 04:52:23

回答

6

在你的js的開始把這個文件

/// <reference path="/js/jquery.js" /> 
在我的IDE版本(NetBeans)
+0

非常感謝,奇妙的作品! – 2012-07-30 05:11:50

+0

您可以將其從「解決方案資源管理器」拖到您的js文件中進行添加。 – Charlie 2012-07-30 05:12:39

+0

這必須在評論中,對吧? – AdityaParab 2012-07-30 05:13:16

0

下面是微軟的智能感知頁面的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; 
} 
相關問題