Official JQuery website
Basic knowledge
JQuery is JavaScript and Query, which is the library that assists JavaScript development.
The file types are divided into the full version and compiled
Use: Create a folder in the file, copy the JQuery package to the folder, and reference
$ Is a special symbol of JQuery that must be written.
Selector
Example:
<Div id = "div1" class = "div1">
<A> aaaaaaaaaaaa </a>
</Div>
<Div class = "div"> </div>
<Div id = "div2"> </div>
Basic Selector
ID selector: $ ("# div1 ")
Class selector: $ ("div ")
Tag Selector
Parallel: Use commas to separate $ ("# div1, # div2" labels can be appended with .css (style)
Descendant: separated by Spaces
Filter Selector
Basic Filter
Beginning and end
$ (". Div: first/last ")
Any
Eq (Index Number) $ (". div: eq ()")
Not equal
Greater
: Gt ();$ (". Div: gt ()")
Less
: Lt ();$ (". Div: lt ()")
Exclude
$ (". Div: not (. div: eq (index number ))")
Parity
$ (". Div: odd/even ")
Attribute name Filtering
$ (". Div [attribute name]")
Content Filtering
Text $ (". div: contains (" string ")")
Child element $ (". div: has (selector )")
Event
Regular events
1. Remove onclick on from js.
Format:
$ (". Div"). click (function (){
}); (Double-click dblclick)
Composite event
$ (". Div"). hover (function (){
Certificate (this).css ("background-color", "red ");
}, Function (){
Certificate (this).css ("background-color", "white ");
}); (BEAM)
$ (". Div"). toggle (function (){
Certificate (this).css ("background-color", "red ");
},Function (){
Certificate (this).css ("background-color", "green ");
},Function (){
((This).css ("background-color", "yellow ");
},Function (){
Certificate (this).css ("background-color", "gray ");
}); (Click to switch continuously)
Event bubbling
Blocking time bubbling:
$ (". Aa"). click (function (){
Return false;
})
DOM operations
Operation content (change content)
$ ("# A"). click (function (){
$ (This). text ("bbbb ");
});
Content Changes in the text box
$ ("# Button"). click (function (){
$ ("# Text box"). val ("changed content ");
$ (This). val ("button changed content ");
})
Add
$ (Document). ready (function (){
Write internally
})
Operation content
Form Element
Value: var s = $ ("selector"). val ()
Value assignment: $ ("selector"). val ("value ")
Non-form Element
Value: var s = $ ("selector" ).html (), var s = $ ("selector"). text ()
Value assignment: $ ("selector" ).html ("content"), $ ("selector"). text ("content ")
Operation attribute
Get attributes: var s = $ ("selector"). attr ("attribute name ")
Set attributes: $ ("selector"). attr ("attribute name", "attribute value ")
Delete attribute: $ ("selector"). removeAttr ("attribute name ")
Operation Style
Operation inline Style
Get style: var s = $ ("selector" ).css ("style name ")
Set style: $ ("selector" ).css ("style name", "value ")
Operate the css of a style sheet
Add class: $ ("selector"). addClass ("class Name ")
Remove class: $ ("selector"). removeClass ("class Name ")
Add and remove alternate class: $ ("selector"). toggleClass ("class Name ")
Operation-related elements
Example: <style type = "text/css">
# Div1 {
Width: 400px;
Height: 400px;
Background-color: red;
}
# Div2 {
Width: 300px;
Height: 300px;
Background-color: blue;
}
# Div3 {
Width: 200px;
Height: 200px;
Background-color: yellow;
}
<Div id = "div1">
<Div id = "div2">
<Div id = "div3">
</Div>
</Div>
</Div>
Search
Parent and predecessors
$ ("Div3"). click (function (){
Var a = $ (this). parent ();
}); (Previous)
Adding. parent after parent is the first level.
$ ("Div3"). click (function (){
Var a = $ (this). parents ("# div1 ");
}); (Predecessors)
Child and younger generation
$ ("Div1"). click (function (){
Var a = $ (this). children (); (sub)
});
$ ("Div1"). click (function (){
Var a = $ (this). find ("# div3 ");(Younger generation)
});
Example:
<Div id = "div1"> </div>
<Div id = "div2"> </div>
<Div id = "div3"> </div>
Brother
Next is followed by an element nextAll (all) (selector) followed by a sibling element.
Prev prevAll (all) (selector)
$ ("Div1"). click (function (){
Var a = $ (this). next (). next ();
});
Operation
New
$ ("HTML string ")
Add
(1) appen (jquery object) add (2) after (,...) lower level add (3) before ("...")Add upper level
Copy
Clone ()
Remove
(1) empty () Clear all internal elements (2) remove () remove elements