jquery can greatly simplify the writing of JavaScript programs
To use jquery, first add a reference to the jquery library in front of the HTML code, such as:
<script language= "javascript" src= "/js/jquery.min.js" ></script>
library files can be either local or directly use the CDN of a well-known company, the advantage is that these large companies are more popular CDN, users visit your site before it is likely to visit other sites have been cached in the browser, so it can speed up the opening of the site. Another benefit is obvious, saving the traffic bandwidth of the website.
The specific wording of the jquery code and the native JavaScript notation differ from the following when performing common operations:
1 positioning elements JS document.getElementById ("abc")
jQuery $ ("#abc") by ID locating $ (". ABC") by using the class Locator $ ("div") via tag positioning
It is important to note that the result of JS return is this element, jquery returns the result is a JS object. The following example assumes that element ABC has been positioned.
2 Changing the contents of an element
js abc.innerhtml = "Test"; &NBSP; jquery&NBSP; abc.html (" test "); Span class= "Apple-converted-space" >&NBSP;
3 Show hidden elements &NBSP;
js abc.style.display = "None"; &NBSP; abc.style.display =" block "; &NBSP;
jquery&NBSP; abc.hide (); &NBSP; abc.show ();
Abc.toggle (); / /toggle between display and hide
4 getting focus
JS and jquery are the same, both Abc.focus ();
5 Assigning a value to a form
js abc.value = "Test"; &NBSP; jquery&NBSP; Abc.val ("test"); &NBSP;
6 Gets the value of the form &NBSP;
js&NBSP; alert (abc.value); &NBSP; jquery&NBSP; alert (Abc.val ()); Span class= "Apple-converted-space" >&NBSP;
7 set element is not available &NBSP;
js abc.disabled = true; &NBSP; jquery&NBSP; Abc.attr ("Disabled", true);
8 Modifying element styles
JS abc.style.fontsize=size; JQuery abc.css (' font-size ', 20);
JS abc.classname= "Test"; JQuery Abc.removeclass (); abc.addclass ("test");
9 Ajax
JS to create their own objects, handle browser compatibility and other messy problems, omit the table
JQuery $.get ("abc.php?a=1&b=2", recall);
Postvalue = "a=b&c=d&abc=123";
$.post ("abc.php", Postvalue, Recall);
function Recall (Result) {alert (Result) and//If JSON is returned, the
is processed as follows
result = eval (' (' + result + ') ');
alert (result); }
10 Determine if check box is selected
JQuery if (abc.attr ("checked") = = "Checked")
Note: Online said. attr ("checked") = = true is not actually used, the above test can be used