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.
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.
Click on the link and you can see the source code of jquery, as follows.
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!