2

我想知道如何将 jquery 导入 .js 文件。我希望能够使用代码提示(智能),但鉴于这是一个单独的文件,我不能这样做。也许我不必导入,但有什么办法得到

$().[hint]

显示在独立的 .js 文件中?

4

2 回答 2

7

把它放在你的 js 文件的开头

/// <reference path="/js/jquery.js" />
于 2012-07-30T05:09:00.690 回答
0

这是 microsoft 关于 javascript 智能感知的页面: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 智能感知的最新支持。如果没有,微软有一个扩展来支持它。要获取上面提到的-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;
}
于 2012-07-30T04:56:03.957 回答