jQuery对象和js对象是怎样转换的?(How are jQuery objects and JS objects converted?)

两种转换方式将一个jQuery对象转换成js对象:[index]和.get(index); (1)jQuery对象是一个数据对象,可以通过[index]的方法,来得到相应的js对象。 如:var $v =$(“#v”) ; //jQuery对象 var v=$v[0]; //js对象 alert(v.checked) //检测这个checkbox是否被选中 (2)jQuery本身提供,通过.get(index)方法,得到相应的js对象 如:var $v=$(“#v”); //jQuery对象 var v=$v.get(0); //js对象 alert(v.checked) //检测这个checkbox是否被选中

js对象转成jQuery对象: 对于已经是一个js对象,只需要用$()把DOM对象包装起来,就可以获得一个jQuery对象了。$(js对象) 如:var v=document.getElementById(“v”); //js对象 var $v=$(v); //jQuery对象 转换后,就可以任意使用jQuery的方法了。

转载:www.cnblogs.com/big-lll/p/6957451.html

注明:此文本只供个人学习

————————

Two conversion methods convert a jQuery object into JS objects: [index] and. Get (index);   (1) JQuery object is a data object. You can get the corresponding JS object through the method of [index].   For example: VAR $v = $(“#v”)// JQuery object   var v=$v[0]; // JS object   Alert (v.checked) / / check whether this checkbox is selected   (2) JQuery itself provides the. Get (index) method to get the corresponding JS object   For example: VAR $v = $(“#v”)// JQuery object   var v=$v.get(0); // JS object   Alert (v.checked) / / check whether this checkbox is selected

< strong > Convert JS object to jQuery object: < / strong >   For an existing JS object, just wrap the DOM object with $() to get a jQuery object$ (JS object)   For example: VAR v = document.getelementbyid (“V”)// JS object   var $v=$(v); // JQuery object   After the conversion, you can use jQuery’s method arbitrarily.

转载:www.cnblogs.com/big-lll/p/6957451.html

Note: This text is for personal learning only