Enable Visual Studio's smart awareness of jquery

Source: Internet
Author: User
Enable Visual Studio's smart awareness of jQuery

First, let's take a look at the smart perception surprises that Visual Studio brings to us. To enable Visual Studio to Support SMART awareness, we need the following conditions:

  • Install VS2008 SP1
    : Http://msdn.microsoft.com/en-us/vstudio/cc533448.aspx
  • Install VS 2008 Patch KB958502 to support the "-vsdoc. js" intelliisense file.
    This patch causes Visual Studio to check whether an optional "-vsdoc. js "file. If it exists, use it to drive the JavaScript intelliisense engine. The "-vsdoc. the js file can contain XML comments for help documents on JavaScript methods, and other code intelliisense prompts for dynamic JavaScript signatures that cannot be automatically inferred. You can learn more about the patch here. You can download the patch "here" for free.
  • The jquery library of vsdoc version must be referenced.
    <script type="text/javascript" src="scripts/jquery-1.3.2-vsdoc2.js"></script>

When writing a script or even entering "$", VS can intelligently prompt:

When using this method, there will be more tips:

With Intelligent Sensing, writing javascript becomes as fast, convenient, and comfortable as C. in most cases, you can write a file successfully at a time without querying the javascript help file for Case sensitivity. the premise that Visual Studio can intelligently perceive jQuery is to introduce the jQuery class library of vsdoc version. in the example, we introduced the "jquery-1.3.2-vsdoc2.js" file. if you reference A jQuery class library of another version, such as min, you cannot enable the smart notification function. however, in the official environment, we must use the jquery library file of the "min" version. Take Version 1.3.2 as an example. The size of each version is as follows:

The first one is the uncompressed jquery library. If you enable gzip compression and use the min version of jquery. js, You can scale the file to 19KB during transmission.

Note: If the script is updated, you can use the "Ctrl + Shift + J" shortcut to update Visual Studio's smart awareness, or click Edit-> intelliisense-> Update JScript intelliisense:

To add a script prompt in Visual Studio and use the script library of the min version when going online, we generally use the following method to introduce the jQuery Library:

1. control compilation results
<script type="text/javascript" src="scripts/jquery-1.2.6.min.js"></script>
<%if (false)
{ %>
<script type="text/javascript" src="scripts/jquery-1.3.2-vsdoc2.js"></script>
<%} %>

This is a recommended method on the Internet. After compilation, only the reference of the min version is available on the page, and smart sensing is available during development. However, pay attention to this method.The referenced min class library can only be 1.2.6 or earlier versions. After referencing all the jquery libraries of the latest 1.3.2 Non-vsdoc version, the JScript intelliisense update error will occur.This is a bug in Version 1.3.2 and is expected to be solved in later versions. In fact, you can use the min library of version 1.2.6. jquery functions involved in this tutorial are basically supported in version 1.2.6.

If (false) is used to make the compiled page not contain references of the jquery library of vsdoc version, the same idea can also be used, for example, to put the script reference into a PlaceHolder and set visible = fasle.

2. Use backend Variables

In order to use the min library of Version 1.3.2, we can only place the Script Reference in the variable and use the page output method to normally update JScript intelliisense. however, some people may not like to use variables at the front end like me:

<asp:PlaceHolder Visible="false" runat="server">
<script type="text/javascript" src="scripts/jquery-1.3.2-vsdoc2.js"></script>
</asp:PlaceHolder>
<% =jQueryScriptBlock %>

Background declaration variables:

protected string jQueryScriptBlock = @"<script type=""text/javascript"" src=""scripts/jquery-1.3.2.min.js""></script>";
 
Enable script intelligent sensing in an independent. JS File

The above solves the problem of intelligent perception on the page. In fact, we can also enable script intelligent awareness in an independent. js file. In the intelliisensedemo. js file, add the following statement:

/// <reference path="jquery-1.3.2-vsdoc2.js" />
 

When you update JScript intelliisense, you will find that smart prompts are also enabled in the script:

Note: The Script smart sensing described in this article is not only applicable to jQuery class libraries, but also to self-compiled javascript code.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.