Home >Web Front-end >JS Tutorial >How to install jquery

How to install jquery

藏色散人
藏色散人Original
2020-11-10 11:29:263834browse

How to install jquery: 1. Download the jQuery library from "jquery.com" and add jQuery to the web page; 2. Load jQuery from CDN, such as loading jQuery from Google.

How to install jquery

The operating environment of this tutorial: windows10 system, jquery1.10.2, this article is applicable to all brands of computers.

Recommended: "jquery video tutorial"

jQuery installation

in the web page Adding jQuery

There are many ways to add jQuery to a web page. You can use the following methods:

  • Download jQuery library from jquery.com

  • Load jQuery from CDN, such as loading jQuery from Google

Download jQuery

There are two versions of jQuery available for download:

  • Production version - For use in actual websites, it has been streamlined and compressed.

  • Development version - for testing and development (uncompressed, readable code)

Both versions above are available from jquery .com download.

The jQuery library is a JavaScript file, you can use the HTML <script> tag to reference it: </script>

<head>
<script src="jquery-1.10.2.min.js"></script>
</head>

Tip: Place the downloaded file in the same directory of the web page, and you can use jQuery.

lamp Are you wondering why we don't use type="text/javascript" in the <script> tag? </script>

In HTML5, you don’t have to do that. JavaScript is the default scripting language in HTML5 and all modern browsers!

Alternatives

If you don't want to download and host jQuery, you can also reference it through a CDN (Content Delivery Network).

Staticfile CDN, Baidu, Youpaiyun, Sina, Google and Microsoft servers all have jQuery.

If your site users are domestic, it is recommended to use domestic CDN addresses such as Baidu, Youpaiyun, Sina, etc. If your site users are foreign, you can use Google and Microsoft.

To reference jQuery from Staticfile CDN, Youpaiyun, Sina, Google or Microsoft, please use one of the following codes:

Staticfile CDN:
<head>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
</head>
百度 CDN:
<head>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
</script>
</head>
又拍云 CDN:
<head>
<script src="https://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.2.min.js">
</script>
</head>

Sina CDN:

<head>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js">
</script>
</head>
Google CDN:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
</head>

lamp No It is highly recommended to use Google CDN to obtain the version, because Google products are very unstable in China.

Microsoft CDN:
<head>
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>
</head>

lamp There is a big advantage in using Staticfile CDN, Baidu, Youpaiyun, Sina, Google or Microsoft's jQuery:

Many users have already started from Baidu when visiting other sites. , Youpaiyun, Sina, Google or Microsoft have loaded jQuery. So the result is that when they visit your site, jQuery is loaded from the cache, which reduces load time. At the same time, most CDNs ensure that when a user requests a file from them, a response is returned from the server closest to the user, which can also improve loading speeds.

jQuery version

We can use the $.fn.jquery command in the browser’s Console window to view the current jQuery version:

How to install jquery

Related free learning recommendations: JavaScript (video)

The above is the detailed content of How to install jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does jquery do?Next article:What does jquery do?