Jquery General Method Introduction

Source: Internet
Author: User

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:
Copy codeThe Code is as follows:
<A href = "www.baidu.com"> click Baidu </a>
<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. $ ('div. foo'). click (function (){
$ ('Span ', this). addClass ('bar ');
})
The html code is
<Div class = "foo"> <span> Haha </span> Haha 2 </div>
<Div class = "foo1"> <span> Haha 3 </span> </div>
<Style>. bar {font-weight: bold} </style>
Click in the div area where class is foo and you will 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 the div 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. <body>
<P> one </p> <div> <p> two </p> </div> <p> three </p>
<Script>
$ ("Div> p" ).css ("border", "1px solid gray ");
</Script>
</Body> // This style is used for the second p.
5. $ ("input: radio", document. forms [0]);
6. $ ("div", xml. responseXML); // find the div in xml. responseXML.
7、((document.body).css ("background", "black ");
8. $ (myForm. elements). hide ()
5. jQuery (html, [ownerDocument]) usage:
(1) $ ("<div/> ",{
"Class": "test ",
Text: "Click me! ",
Click: function (){
$ (This). toggleClass ("test ");
}
}). AppendTo ("body ");
Or
$ ("<Div/>"). attr {
"Class": "test ",
Text: "Click me! ",
Click: function (){
$ (This). toggleClass ("test ");
}
}). AppendTo ("body ");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.