Here are some of my share, I love programming, hope to be able to pay more programming enthusiasts, if you are also one of them, then please add friends, we pay attention to, the following article is that they feel some useful things, stay to yourself as a note, of course, also hope to help you, first of all thank you for your reading ~!
If we use jquery as a script for the client page, we often refer to the mutual conversion of jquery objects and JavaScript objects. Because DOM objects are some object operations that are intrinsic to JavaScript. DOM objects can use the intrinsic methods of JavaScript, but they cannot use the methods in JQuery. Therefore, we in Guangzhou the share a little bit between their conversion code for everyone to learn and reference.
1. DOM objects Turn into JQuery objects
For a DOM object, you can get a JQuery object by wrapping the DOM object with $ (), $ (DOM object)
such as: var v = document.getElementById ("V"); Dom Object
var $v = $ (v); JQuery objects
After conversion, you can use the JQuery method as you like.
2. JQuery objects Turn into DOM objects
Two conversions speak of a JQuery object converted to a DOM object: [index] and. get (index);
(1) The JQuery object is a data object, which can be obtained through the method of [index] to get the corresponding DOM object.
such as: var $v = $ ("#v"); JQuery objects
var v = $v [0]; DOM Object
alert (v.checked); Detect if this checkbox is selected
(2) JQuery itself provides the corresponding DOM object through the. Get (Index) method
such as: var $v = $ ("#v"); JQuery objects
var v = $v. Get (0); Dom objects ($v. get () [0] can also)
alert (v.checked); Detect if this checkbox is selected