jquery Event Handling
Ready (FN)
Code:
$ (document). Ready (function () { Your code here ... }); |
Role: It can greatly improve the response speed of Web applications. By using this method, you can immediately call the function you are binding when DOM loading is ready to be read and manipulated, and 99.99% of JavaScript functions need to be executed at that moment.
Bind (TYPE,[DATA],FN)
Code:
$ ("P"). Bind ("click", Function () { Alert ($ (this). text ());
|
Function: Bind an event handler function to a specific event (like click) for each matching element. Play the role of event monitoring.
Toggle (FN,FN)
Code:
$ ("TD"). Toggle ( function () { $ (this). AddClass ("selected"); }, function () { $ (this). Removeclass ("selected"); } ); |
function: Switch the functions you want to call each time you click. If a matching element is clicked, the first specified function is triggered, and when the same element is clicked again, the specified second function is triggered. A very interesting function that may be used when implementing certain functions dynamically. (Like click (), focus (), KeyDown () such events are not mentioned here, those are more commonly used in development. )
jquery appearance effect
AddClass (Class) and Removeclass (class)
Code:
$ (this). Removeclass ("Over");}) });
|
Can also be written as:
$ (". Stripe tr"). MouseOver (function () {$ (this). addclass (' over ')}); $ (". Stripe tr"). Mouseout (function () {$ (this). Removeclass (' over ')}); |
Action: Adds or removes styles for the specified element to achieve a dynamic style effect, which enables the mouse to move the two-color table code in the above instance
CSS (Name,value)
Code:
$ ("P"). CSS ("Color", "red"); |
Function: It is very simple to set the value of a style attribute in the matching element. This personal feeling is somewhat similar to the AddClass (class) above.
Slide (), Hide (), FadeIn (), fadeout (), Slideup (), Slidedown ()
Code:
$ ("#btnShow"). Bind ("click", Function (event) {$ ("#divMsg"). Show ()}); $ ("#btnHide"). Bind ("click", Function (evnet) {$ ("#divMsg"). Hide ()}); |
Role: A function of the more commonly used dynamic effects provided in jquery. You can also add Parameters: Show (Speed,[callback]) displays all matching elements in an elegant animation, and optionally triggers a callback function when the display is complete.
Animate (Params[,duration[,easing[,callback]])
Function: Make animation effect to use functions, the function is very powerful, you can use this function continuously.
Find Filter
Map (callback)
HTML Code:
Values:
< INPUT Value=john name=name> < INPUT Value=password name=password> < INPUT value= "< A href=" Name=url? %22 ejohn.org http:>http://ejohn.org/%22/</a>
< form> |
JQuery Code:
$ ("P"). Append ($ ("input"). Map (function () { return $ (this). Val ();
|
Results:
[John, Password, < A href= "http://ejohn.org/%3C/p" >http://ejohn.org/%3C/p</a>>] |
Action: Converts a set of elements into other arrays, whether or not an element array, you can use this function to create a list, whether it's a value, a property, a CSS style, or some other special form. This can be used ' $.map () ' to facilitate the establishment.
Find (expr)
HTML Code:
< span>hello</span> how are are you?JQuery Code:
Results:
[< span>hello</span>] |
Function: Searches for all elements that match the specified expression. This function is a good way to find the descendant elements of the element being processed.
Document processing
HTML Code:
JQuery Code:
$ ("img"). attr ("src", "test.jpg"); |
Function: Gets or sets the property value of the matching element. This method makes it easy to get the value of a property from the first matching element. Returns undefined if the element does not have a corresponding property. is an essential tool for controlling HTML tags.
HTML ()/html (Val)
HTML Code:
JQuery Code:
$ ("div"). html ();
Results:
Hello
Function: Gets or sets the HTML content of the matching element, and the same type of method has text () and Val (). The former is the content that gets all the matching elements. , which is the current value for the matching element. The three have similar places commonly used in the operation of the contents.
Wrap (HTML)
HTML Code:
Test Paragraph.
JQuery Code:
$ ("P"). Wrap ("
Results:
< DIV class=wrap>
Test Paragraph.
|
Function: Wrap all matching elements in a structured notation of other elements. This wrapper is most useful for inserting additional structured markup into a document, and it does not break the semantic quality of the original document. We have the flexibility to modify our DOM.
Empty ()
HTML Code:
Person < A href= "http://www.jb51.net#" >and person</a>
|
JQuery Code:
$ ("P"). empty ();
Results:
Action: Deletes all child nodes in a matching set of elements.
Ajax processing
Load (Url,[data],[callback])
URL (String): To be loaded into the HTML Web site.
Data (MAP): (optional) Key/value to the server.
Callback (callback): (optional) callback function when successfully loaded.
Code:
$ ("#feeds"). Load ("Feeds.aspx", {limit:25}, function () { Alert ("The last entries in the feed have been loaded"); }); |
Function: Loads the remote HTML file code and inserts it into the DOM. This is also the most common and effective method of jquery operation Ajax.
Serialize ()
HTML Code:
Results:
< form>
< option>single2</option> </select>
< option>multiple2</option> < OPTION selected>multiple3</option> </select> < INPUT value=check1 Type=checkbox name=check> check1
checked= "Checked"/> Check2
checked= "Checked"/> Radio1 < INPUT Value=radio2 Type=radio name=radio> Radio2 </form> |
JQuery Code:
Function: Serializes the contents of a table as a string. For Ajax requests.
Tools
Jquery.each (Obj,callback)
Code:
$.each ([0,1,2], function (i, n) { Alert ("Item #" + i + ":" + N); });//traversal array $.each ({name: "John", Lang: "JS"}, function (i, n) { Alert ("Name: + i +", Value: "+ n")//Traverse Object }); |
Function: A general method of routine, which can be used for the example of objects and arrays.
Jquery.makearray (obj)
HTML Code:
The< div>second</div>
third</div>
< Div>fourth
</div>
|
JQuery Code:
var arr = Jquery.makearray (document.getElementsByTagName ("div")); |
Results:
Fourth
Third
Second
The
Function: Converts an array object of a class to an object. Allows us to make flexible conversions between arrays and objects.
Jquery.trim (str)
Role: This should be very familiar to you, is to remove the beginning and end of the string space.
Summary: In the actual development we may use other methods and attributes, the above is only the individual thinks the novice begins to learn jquery, must master some methods. Only for everyone to learn the reference. What is wrong with the expert advice.