Introduction to jquery general methods Getting started reference_jquery
- WBOYOriginal
- 2016-05-16 18:05:401139browse
1. event.preventDefault(): Prevent an event from happening. For example, when a link is clicked, it will jump to the linked page. If you want to avoid this function, you can use this method. For example:
Click Baidu <script> <br> $(document).read(function(){ <br> $("a").click(function(event){ <br> event.preventDefault(); //The effect is that when the above link is clicked, the page remains unchanged. <br> }) <br> }) <br> </script> 2. The hide() method, as the name suggests, is a hidden method. If you add $(this).hide() below in the above example, the four words "Baidu" will disappear when you click on it. If you add $(this).hide("slow"), you can find that the four words "Baidu" will slowly disappear when you click on them.
3. How to use callback. callback is the so-called callback function, which is executed only after the parent function is executed. Examples are as follows:
(1) When the callback function has no parameters, directly $.get("dd.html",mycallback);
(2) When the callback function includes parameters, $.get("dd.html ",function(){
mycallback(param1,param2);
})
) method is passed as the second parameter of the get() method to execute the get() method.
4. Usage of jquery(selector,[context]):
1. $('div.foo').click(function(){
$('span',this).addClass( 'bar');
})
The html code is
div class="foo1">
Haha3 Click within the div area of foo, and you will find that the word "haha" has become thicker, while the rest of the words remain the same, because the above script code indicates that the addClass operation can only be triggered in the span in the div with class 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 its content in the variable of data, and then store the content of the child node in data. Enter the variable $child
4.
/p>
<script> <br> $("div > p").css("border", "1px solid gray"); <br> </script>
body> //The effect is that the second p adopts this 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. Usage of jQuery (html, [ ownerDocument ]):
(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");