1. Download
Official website is http://jquery.com/
Http://docs.jquery.com/Downloading_jQuery
You can download the current and historical versions and deploy them on your own server.
The Google \ Microsoft \ jQuery CDN (Content Delivery Network) address is also listed above. Because jQuery is widely used, you can select a CDN address to make full use of the cache and the bandwidth and server resources of these Internet giants.
The official website contains two versions: Compressed (Minified version) and Uncompressed (Source version)
The size of the former is about 70 KB and less than half the size of the uncompressed version.
However, uncompressed versions make it easier to read the source code and debug it.
Ii. Installation
It is very easy to install jQuery. You only need to reference the js file you downloaded in HTML.
For example, <script type = "text/javascript" src = "/jslibs/jquery. min. js"> </script>
Directly reference <script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>
3. The first program
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>
<Script type = "text/javascript">
$ (Function () {alert ("hello ");})
</Script>
</Head>
<Body>
</Body>
</Html>
After refreshing the page, you can execute it.
At the beginning, it may be a little uncomfortable with $. In fact, it will take a long time to get used to it and like its conciseness. If you cannot afford it, you can replace "$" with "jQuery ".
Copy codeThe Code is as follows: $ (function () {alert ("hello ");})
Equivalent
Copy codeThe Code is as follows: $ (document). ready (function () {alert ("hello ");})
It is also basically equivalent
Copy codeThe Code is as follows: document. onready = function () {alert ("hello ");}
That is to say, after the browser completely parses the document structure, it can execute the following statement.
The difference between onload and document. onload is that onload not only needs to parse the document structure, but also waits until all the content to be loaded is loaded (such as parts)
Because $ (document). ready (fn) is frequently used, it can be simplified to $ (fn)