It is a good learning reference for friends who are new to jquery, and some methods are also described. 1. event. preventDefault (): block an event. For example, if you click a link, it usually jumps to the linked page. To avoid this function, you can use this method. For example:
The Code is as follows:
Click Baidu
Script
$ (Document). read (function (){
$ ("A"). click (function (event ){
Event. preventDefault (); // The effect is that the page remains unchanged when you click the above link.
})
})
Script
2. The hide () method, as its name implies, is a hidden method. If $ (this). hide () is added below in the above example, the words Baidu will disappear. If you add $ (this). hide ("slow"), you can find that clicking Baidu will slowly disappear.
3. callback usage. Callback is called a callback function. It is executed only after the parent function is executed. Example:
(1) When the callback function has no parameters, $. get ("dd.html", mycallback );
(2) When the callback function includes parameters, $. get ("dd.html", function (){
Mycallback (param1, param2 );
})
Do not write $. get ("dd.html", mycallback (param1, param2); the program will pass the value returned by the mycallback () method as the second parameter of the get () method to execute get () method.
4. Usage of jquery (selector, [context:
1. $ ('p. foo'). click (function (){
$ ('Span ', this). addClass ('bar ');
})
The html code is
Hahahaha 2
Haha 3
In the p region where class is foo, you can find that the characters Haha have become crude, and the remaining words remain unchanged, because the script code above indicates that the addClass operation can be triggered only in the span of p whose class is foo.
2. $ (this): If you can add $ (this). slideUp () in the above script code ().
3. $. post ('url. xml', function (data ){
Var $ child = $ (data). find ('child ');
}) // When loading url. xml, store the content to the data variable, and then store the content containing the child node in the variable $ child.
4,
One
Two
Three
Script
$ ("P> p" ).css ("border", "1px solid gray ");
Script
// This style is used for the second p Effect
5. $ ("input: radio", document. forms [0]);
6. $ ("p", xml. responseXML); // locate p in xml. responseXML
7、((document.body).css ("background", "black ");
8. $ (myForm. elements). hide ()
5. jQuery (html, [ownerDocument]) usage:
(1) $ ("
",{
"Class": "test ",
Text: "Click me! ",
Click: function (){
$ (This). toggleClass ("test ");
}
}). AppendTo ("body ");
Or
$ ("
"). Attr {
"Class": "test ",
Text: "Click me! ",
Click: function (){
$ (This). toggleClass ("test ");
}
}). AppendTo ("body ");