jquery General Method Introduction Reference _jquery

Source: Internet
Author: User
1, Event.preventdefault (): To prevent the occurrence of an event. such as a link, click on the general will jump to the linked page, if you want to circumvent this function, you can use this method. Such as:
Copy Code code as follows:

<a href= "Www.baidu.com" > click Baidu </a>
<script>
$ (document). Read (function () {
$ ("a"). Click (Function (event) {
Event.preventdefault (); The effect is that when you click on the link above, the page stays still.
})
})
</script>

2, Hide () method, as the name implies, the hidden method, if the above example in the following plus $ (this). Hide (), then click Baidu Four words will disappear. If you add $ (this). Hide ("slow"), you can find, click Baidu Four words will slowly disappear.
3, the use of callback. Callback is called a callback function that executes only when the parent function finishes executing. Examples are as follows:
(1) When the callback function has no parameters, direct $.get ("dd.html", mycallback);
(2) When a callback function includes a parameter, $.get ("dd.html", function () {
Mycallback (PARAM1,PARAM2);
})
Avoid writing $.get ("dd.html", Mycallback (PARAM1,PARAM2)); The program passes the value returned by the Mycallback () method as the second parameter of the Get () method to execute the Get () method.
4, the use of jquery (Selector,[context]):
1, $ (' Div.foo '). Click (function () {
$ (' span ', this). addclass (' Bar ');
})
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 of class Foo, you can find that haha two words become thicker, the rest of the word remains the same, because the script code above indicates that in the span of the div with class Foo, the addclass operation can be raised.
2, $ (this): If you can add $ (this) to the script code above. Slideup ().
3, $.post (' Url.xml ', function (data) {
var $child = $ (data). Find (' child ');
}//Loading Url.xml, the contents are stored in the variable of data, and then the content containing the child node in data is stored 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>//effect for the second P adopted the style
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");

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.