1. Using jquery
To jquery.com download Jquery.js current version is 1.4.2
Create a new HTML page
Copy Code code as follows:
<! DOCTYPE html><br><pre class=brush> <script type= "Text/javascript" ><BR> < SPAN style= "color: #ff0000" > $ (document). Ready (function () {</span><br><span style= "color: #ff0000" > $ ("a"). Click (Function (event) {</span><br><span style= COLOR: #ff0000 "> alert (" As you can, the link no longer took Jquery.com "); </span><br><span style=" COLOR: #ff0000 "> Event.preventdefault () </span><br><span style= "COLOR: #ff0000" > }); </span><br><span style= "COLOR: #ff0000" > }); </ span><br> <BR> </script><br>
Code Explanation:
$ (document). Ready (function () {...}) Add function () content when a page finishes loading
$ ("a"). Click (Function (Event) {...}) Set the Click event function for a label
Event.preventdefault () prevents the original event from executing
Code function: Click <a> tag only pop-up alert information, the page does not jump to http://jquery.com/.
2. Adding and Removing HTML class
First, add a few styles to
Copy Code code as follows:
<style type= "Text/css" >
a.test {font-weight:bold;}
</style>
Use AddClass and Removeclass in script to add and remove HTML class, for example:
Copy Code code as follows:
$ ("a"). AddClass ("test");//All a marked bold
$ ("a"). Removeclass ("test");//Cancel all a marked bold
3. Special effects
jquery offers some very handy effects.
Copy Code code as follows:
$ ("a"). Click (Function (event) {
Event.preventdefault ();
$ (this). Hide ("slow");
});
After clicking on the <a> tag, the tag disappears slowly
4. Callbacks and functions
No parameter callback
Copy Code code as follows:
$.get (' myhtmlpage.html ', mycallback);
Callback with parameter
Copy Code code as follows:
$.get (' myhtmlpage.html ', function () {
Mycallback (param1, param2);
});