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");