Enable Visual Studio's smart awareness of jquery

Source: Internet
Author: User
Tags jquery library
ArticleDirectory
    • 1. control compilation results
    • 2. Use backend Variables
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. These annotated "-vsdoc. js" files can contain XML comments for the help document for Javascript methods, and additional information for dynamic JavaScript signatures that cannot be automatically inferredCodeIntelliisense prompt. 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 )
{%>

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 =  @ "" ; 
 


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.