Home  >  Article  >  Web Front-end  >  How to introduce jquery?

How to introduce jquery?

little bottle
little bottleOriginal
2019-05-29 13:44:5939838browse

jquery is a library used to quickly write front-end scripting language instead of JavaScript. jquery can greatly simplify complex js code, allowing developers to focus on achieving the effect of the page.

How to introduce jquery?

Import method

There are two ways to import jquery, one is to import locally and the other is to import from Hyperlink import.

Related topic recommendations: "jQuery Tutorial"

Method 1: Local import

We can search jquery on Baidu, you can Search the official website of jquery:

https://jquery.com/

From here you can download the latest version of jquery. Click the download icon and it will jump to the download details page.

How to introduce jquery?

Click on the link and you can see the source code of jquery, as follows.

How to introduce jquery?

We directly ctrl a, select all, create a new txt file, copy the source code into it, and then change the suffix to .js.

Next, we introduce this .js file into the page where we want to use jquery. The code is as follows:

<script src="你的.js文件路径"></script>
<script>
	//在此书写你的jquery代码
</script>

Attention

Attention! Be sure to write the imported script first and then your own jquery code, because the loading order of the page is from top to bottom. The browser will load your jquery code first and then the jquery library, causing your jquery code to be considered an error. The writing format cannot achieve the effect.

Method 2: Import online jquery

We can import the online jquery code by writing a URL in the src attribute of the script.

In fact, there are many websites that use jquery now. The browser will pre-download jquery when loading the website that used jquery before, so we don’t need to download it again, even if our jquery version is It is a new version that has not been loaded by the browser, and the jquery code will be downloaded very quickly. However, if you are still worried about affecting the loading speed, importing the jquery file locally is indeed the best way.

Import online jquery:

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
	//在此书写你的jquery代码
</script>

The above is the detailed content of How to introduce 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