Home > Web Front-end > Front-end Q&A > Which file does jquery need to import?

Which file does jquery need to import?

青灯夜游
Release: 2023-01-04 09:16:16
Original
2671 people have browsed it

You need to import the jquery.js file before using jquery. Two import methods: 1. Download the jquery file locally from the jquery official website, and use the script tag to import the local jquery file. The syntax is ""; 2. Use script The tag imports the online jquery file with the syntax "".

Which file does jquery need to import?

The operating environment of this tutorial: windows7 system, jquery3.6 version, Dell G3 computer.

1. Introduction to jQuery

  • ##jQuery is a js library that stores function() written in js code .

  • The original intention of jQuery is to simplify JS code.

  • Can handle HTML/JSP/XML, CSS, DOM, events, and also provide asynchronous AJAX functionality.

  • For example:

    document.getElementByid() Encapsulates a method in jQuery:

  • function $("#id"){//函数名是$
    	return document.getElementById(id);
    }
    Copy after login

2. Use:

jQuery is actually a js file. When we use it, we first need to introduce the file into the HTML document. There are two ways to import jquery, one is local import and the other is import from hyperlink.

Introduction method one: local introduction

We can search jquery on Baidu and find the official website of jquery: https://jquery.com/

You can download the latest version of jquery from here. Click the download icon and you will jump to the download details page:

Which file does jquery need to import?

The first two links here are for two versions. jquery download, one is a compressed version and the other is an uncompressed version. There is no functional difference between the two versions. It is just that the compressed version has been deleted in order to take up less space for jquery when publishing the project. Extra spaces and line breaks are used to achieve the purpose of streamlining. As developers, we have not yet reached the stage of publishing the project, so we just choose the second uncompressed version.

Click on the link and you can see the source code of 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="本地jquery文件路径"></script>
<script>
	//在此书写你的jquery代码
</script>
Copy after login

Which file does jquery need to import?

Which file does jquery need to import?

Note ! 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.

Introduction method two: introduce online jquery

We can import the online jquery code by writing a URL in the src attribute of the script. Someone may want to ask, Wouldn't this cause a delay in downloading jquery when the web page is loading? Will it take a long time to download, causing your jquery code to never be loaded, affecting the user experience?

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.

For example, the online JQ file of jquery official website: https://code.jquery.com/jquery-3.6.0.min.js

Which file does jquery need to import?

Import online jquery:

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	//在此书写你的jquery代码
</script>
Copy after login

Usage:

Create jQuery objects to call functions in the library

[Recommended learning:

jQuery video tutorialwebfront-end video

The above is the detailed content of Which file does jquery need to import?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template