| The code is as follows |
Copy Code |
| <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <title> Untitled Page </title> <script src= ". /script/jquery-1.3.2.min.js "type=" Text/javascript "> </script> <script type= "Text/javascript" > $ (function () { $ ("#Button1"). Bind ("click", Function () { This is the currently clicked object Alert ($ (this). attr ("name")); }) }) </script> <body> <input id= "Button1" name= "Ws_hgo" type= "button" value= "button"/> </body>
|
The transformation of jquery objects and Dom objects
These are DOM objects that can use the methods in the DOM, but no longer use the jquery method.
The following are the correct ways to do this:
| The code is as follows |
Copy Code |
$ ("#msg"). html (); $ ("#msg") [0].innerhtml; $ ("#msg"). EQ (0) [0].innerhtml; $ ("#msg"). Get (0). InnerHTML; |
Ordinary DOM objects can generally be converted to jquery objects by $ ().
Such as:
$ (document.getElementById ("MSG")) is a jquery object, and you can use the jquery method.
Because the jquery object itself is a collection. So if the jquery object is to be converted to a DOM object, one of these items must be removed, which is generally accessible through the index.
Other reference
Some methods of the core of jquery
Each (callback) ' is like a loop
$ ("Element"). Length; ' The number of elements, is a property
$ ("Element"). Size (); ' is also the number of elements, but with parentheses is a method
$ ("Element"). get (); ' A collection of elements in a page, stored as an array
$ ("Element"). Get (index); ' function is the same as above, index represents the first few elements, the subscript of the array
$ ("Element"). Get (). reverse (); ' Put the resulting array in the direction
$ ("Element1"). Index ($ ("Element2")); ' The index value of element 2 in element 1 is ...
4, basic object acquisition
$ ("*") ' means get all objects
$ ("#element") ' Get the same ID number as in CSS
$ (". ABC") ' all elements using the. ABC Style
$ ("div") ' tag Selector Select all DIV elements
$ ("#a,. B,span") ' means the element that gets ID A and the element that uses class style B, and all span elements
$ ("#a. B p") ' ID number is a and all p elements of B-style are used
5. Level element Acquisition
$ ("Element1 Element2 Element3 ...") ' Front parent is a subset
$ ("div > P") ' Get all the P elements underneath the div
$ ("div + P") ' div element after the first P element
$ ("div ~ p") ' div after all the P elements