Jquery
Official site:
1.2
By learning this document, you can
Ii. Usage
Before using
For example:
After the introduction, you can use it anywhere on the page.
Iii. Learning tutorials and references
See 《
Two good articles are recommended.
(
Iv. Syntax summary and precautions
1
Pass
2
Only
Common
For example:
Because
For example:
The following statements are correct:
$ ("# Msg" cmd.html ();
$ ("# Msg") [0]. innerHTML;
$ ("# Msg"). eq (0) [0]. innerHTML;
$ ("# Msg"). get (0). innerHTML;
3
You can use
$ ("Div" 2.16.eq(22.16.html ();//
$ ("Div"). get (2). innerHTML ;//
4
Jquery
$ ("# Msg" cmd.html ();//
$ ("# Msg" cmd.html ("<B> new content </B> ");
//
$ ("# Msg"). text ();//
$ ("# Msg"). text ("<B> new content </B> ");
//
$ ("# Msg"). height ();//
$ ("# Msg"). height ("300 ");//
$ ("# Msg"). width ();//
$ ("# Msg"). width ("300 ");//
$ ("Input"). val (");//
$ ("Input"). val ("test ");//
$ ("# Msg"). click ();//
$ ("# Msg"). click (fn );//
Similarly
5
For
There are two forms:
$ ("P"). each (function (I) {this. style. color = ['# f00',' #0f0 ',' # 00f']})
//
$ ("Tr"). each (function (I) {this. style. backgroundColor = ['# ccc', '# fff'] [I % 2]})
//
$ ("P" ).click(function(){alert(((this).html ())})
//
6
$. Extend ({
Min: function (a, B) {return a <B? A: B ;},
Max: function (a, B) {return a> B? A: B ;}
});//
Use the extension method (through
Alert ("a = 10, B = 20, max =" + $. max (10, 20) + ", min =" + $. min (10, 20 ));
7
The so-called write-in means that
For example:
$ ("P" ).click(function(){alert(((this).html ())})
. Mouseover (function () {alert ('mouse over event ')})
. Each (function (I) {this. style. color = ['# f00',' #0f0 ',' # 00f']});
8
It mainly includes the following methods:
$ ("# Msg" ).css ("background ");//
$ ("# Msg" ).css ("background", "# ccc ")//
$ ("# Msg"). height (300); $ ("# msg"). width ("200 ");//
$ ("# Msg" ).css ({color: "red", background: "blue "});//
$ ("# Msg"). addClass ("select ");//
$ ("# Msg"). removeClass ("select ");//
$ ("# Msg"). toggleClass ("select ");//
9
Jquery
For example:
$ ("# Msg"). click (function () {alert ("good ")})//
$ ("P"). click (function (I) {this. style. color = ['# f00',' #0f0 ',' # 00f']})
//
JQuery
(
//
$ ("Tr"). hover (function (){
$ (This). addClass ("over ");
},
Function (){
$ (This). addClass ("out ");
});
(
$ (Document). ready (function () {alert ("Load Success ")})
//
(
//
$ ("P"). toggle (function (){
$ (This). addClass ("selected ");
}, Function (){
$ (This). removeClass ("selected ");
});
(
For example:
$ ("P"). trigger ("click ");//
(
Deletes a bound event from each matching element.
For example:
$ ("P"). bind ("click", function () {alert ($ (this). text ());});//
$ ("P"). unbind ();//
$ ("P"). unbind ("click ")//
10
Where
For example
SlideToggle ()
11
$. Browser.
$. Each (obj, fn)
For example
$. Each ([0, 1, 2], function (I, n) {alert ("Item #" + I + ":" + n );});
It is equivalent:
Var tempArr = [0, 1, 2];
For (var I = 0; I <tempArr. length; I ++ ){
Alert ("Item #" + I + ":" + tempArr );
}
It can also be processed
$. Each ({name: "John", lang: "JS"}, function (I, n) {alert ("Name:" + I + ", Value: "+ n );});
Result:
Name: name, Value: John
Name: lang, Value: JS
$. Extend (target, prop1, propN)
For example:
$. Extend (settings, options );
//
Var settings = $. extend ({}, defaults, options );
//
There can be multiple parameters (merging multiple parameters and returning them)
$. Map (array, fn)
For example:
Var tempArr = $. map ([0, 1, 2], function (I) {return I + 4 ;});
TempArr
Var tempArr = $. map ([0, 1, 2], function (I) {return I> 0? I + 1: null ;});
TempArr
$. Merge (arr1, arr2 ):
For example:
$. Trim (str)
For example:
12
Many times we have defined
Use
For example:
JQuery. noConflict ();
//
JQuery ("div p"). hide ();
//
$ ("Content"). style. display = 'none ';
Nobody gets to write your destiny but you.