jQuery获取的dom对象和原生的dom对象

<div id="box"></div>
<!--原生的js-->
var a=document.getElementById('aaa') 
   console.log(a)//<div id="box"></div>
   console.log(a[0] instanceof Object)//true
var b=$('#aaa')
   console.log(b)//jquery.fn.init[]
   console.log(b instanceof Object)true
 我们可以看出原生的js打印的是普通的dom结构,但是jquery打印的是一个数组对象,对象内有很多的信息
 原生DOM对象转jQuery对象:
var box = document.getElementById('box');
var $box = $(box);
jQuery对象转原生DOM对象:
var $box = $('#box');
var box = $box[0];复制代码

转载于:https://juejin.im/post/5d07341df265da1bcb4f2c5e

猜你喜欢

转载自blog.csdn.net/weixin_33940102/article/details/93176446