What is jQuery?

JQuery is a JavaScript library. JQuery is a JavaScript framework that defines its own syntax

(1) Strong compatibility, do not have to consider the compatibility problems of firefox, IE6, IE7, IE8, Safari, Opera and other browsers (2) Perfect Ajax application, Ajax becomes simple (3) DOM operation is simple (4) rich plug-in support, strong scalability; Write less, but do more.

2. Introduction of jQuery

No need to add “type=text/javascript” 1.2,

3. Start jQuery

1. First import the jQuery library in the head TAB

2. “$” (jQuery) dollar sign

$. Post = $.post = $.postCopy the code

The $() constructor

(1) $() is the jQuery() function, usually referred to as the "selector function" of jQuery. (2) The selectors in parentheses are used to select HTML elements. (3) The $() function automatically loops through the HTML elements selected in parentheses and returns a jQuery object.Copy the code

4, jQuery object writing method

$(document).ready(); $(document).ready(); $(document).ready(); The $(document). Ready (function () {/ / - add jQuery code here -}); Simplified writing: $(function () {/ / - add jQuery code here -}); Function (){$(document).ready(function(){})Copy the code

JQuery comments are divided into single-line comments and multi-line comments. Single-line comments are // CTRL +/ multi-line comments are /* */ CTRL + Shift +/

$(document).ready(function(){})

1. Execution timing

$(document).ready(function(){})==== Perhaps the ones associated with the DOM element are not fully loaded

2. Write numbers

Window.onload ==== cannot write more than one $(document).ready(function(){})==== can write more than one, and all execute

3. Simplify writing

$(document).ready(function(){}) $(function(){})

5. The difference between JavaScript DOM objects and jQuery objects

JavaScript obtains objects through js related object methods such as getElementById(), getElementsByClassName, getElementsByTagName, and getElementsByName

Var $aObj=$(” #one “).html() // Get the HTML of the object named one. Equivalent to: var aObj= document.getelementById (” one “).innerhtml;

Note: You cannot apply any methods of DOM objects to jquery objects or vice versa

Conversion between jQuery objects and JavaScript objects

Var $cr = $(” #cr “); var cr = $cr[0];

Var $cr = $(” #cr “); var cr = $cr.get(0)

Var cr = document.getelementById (” cr “); var cr = document.getelementById (” cr “); var $cr = $(cr); \

7. Basic grammar

$(selector).action()

$("#go") -- select all elements whose ID ="go" (4) action() : Hide () -- perform the hide operation -- $("#go").hide() -- select all elements with id="go" and perform the hide operation; That is, hide all elements with id="go"

2, chain grammar: $(selector). The action () the action () the action ()...Copy the code

Note: The selected element executes the first action() method, followed by the second action() method, then the third action() method, and so on…… This is the chain operation that jQuery features.