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];複製代碼
相關文章
相關標籤/搜索