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 placed on-premises, 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.
Provided by Google
Http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js
The official jquery
Http://code.jquery.com/jquery-1.6.min.js
I've got my own subdomain, and I'm actually jumping to Google's Cdn.
Http://cdn.akcms.com/js/jquery.js
The specific wording of the jquery code and the native JavaScript notation differ from the following when performing common operations:
1 anchor element
js
document.getElementById ("abc")
jquery
$ (" #abc ") locates by ID,
$ (". ABC ") is positioned by class,
$ (" div ") is positioned by tag;
Note that the result of JS return is this element, The result of JQuery's return is a JS object. The following example assumes that element ABC has been positioned.
2 Change the contents of the element
js
abc.innerhtml = "Test";
jquery
abc.html ("test");
3 Show hidden elements
js
Abc.style.display = "None";
Abc.style.display = "block";
jquery
Abc.hide ();
Abc.show ();
Abc.toggle ();
Toggle between show and hide (2012.4.21 update)
4 getting Focus
JS and jquery are the same, both Abc.focus ();
5 Assigning a value to a form
Js
Abc.value = "Test";
Jquery
Abc.val ("test");
6 Getting the value of a form
Js
alert (Abc.value);
Jquery
Alert (Abc.val ());
7 setting elements are not available
Js
Abc.disabled = true;
Jquery
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
Create objects themselves, 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);
If the JSON is returned, the following processing
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
Source: http://www.2cto.com/kf/201405/301890.html
The difference between JS and jquery