Home  >  Article  >  Web Front-end  >  First introduction to Jquery and its usage

First introduction to Jquery and its usage

一个新手
一个新手Original
2017-09-25 09:45:281359browse

1. Several disadvantages of js:

1. There can only be one entry function for js, and the latter one will overwrite the previous one, and it will only be executed after all the resources on the page have been loaded. J

2. It’s troublesome to find the object, the method is single

3. Manually write the for loop

4. There are compatibility issues with native js

5. The code The fault tolerance rate is not high. Once an error is reported, it will not be executed later

6. It is troublesome to implement animation with js. Manual encapsulation


##2. Advantages of JQuery

1. Lightweight. 100k, more than a dozen kilobytes after compression.

2. Powerful selector. css selector + jquery comes with selector

3. Excellent Dom operation encapsulation

4. Reliable event processing mechanism

in reserved fallback (graceful degradation) , Step-by-step and Unobtrusive programming ideas have been done quite well

5. Perfect Ajax

$.ajax()

6. Do not pollute top-level variables

7. Excellent browser compatibility.

8. Chain operation method

You can write directly without repeatedly obtaining the object

9.Implicit iteration

The methods in jQuery are all designed to Automatically operate object collections instead of individual objects, a large number of loops are no longer necessary, and the amount of code is greatly reduced

10. Separation of behavior layer and structure layer

11. Rich plug-in support

12. Complete documentation

13. Open source

jQ writing method:

1、引包 script src ="jquery-1.12.4.js"
2、入口函数($()===jQuery(),$是jQuery的一个简写形式
简写:$(function(){
});
$(document).ready(function(){//等待dom元素加载完毕
alert('Hello World!');//弹出警告框
};

is similar to window.onload, but window.load must wait It can only be executed after all the content of the web page (including pictures) has been loaded, and multiple executions cannot be performed. The latter covers the former

*tips:The essence of $, $(); function call

parameters , you can use three types

1)func;

2)Function name

3)String: "p";

The above is the detailed content of First introduction to Jquery and its usage. 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