深入淺析jQuery對象$.html
$對象
說起jQuery,最明顯的標(biāo)志,毫無疑問,就是, ,其實(shí)是jquery的簡寫。而使用$()包裝的對象就是jQuery對象
與jQuery對象相對應(yīng)的就是DOM對象,DOM對象其實(shí)就是DOM元素節(jié)點(diǎn)對象
如果直接寫document,則指的是document的DOM元素對象
document.onclick = function(){
alert('dom');
}
而如果用()包括起來,如 ()包括起來,如(document),是jQuery(document)的簡寫形式,則指的是jQuery對象
<script src="jquery-3.1.0.js"></script> <script> console.log(jQuery(document));//[document] console.log($(document));//[document] console.log(document);//#document </script>
[注意]jQuery對象無法使用DOM對象的方法,DOM對象也無法使用jQuery對象的方法
<script src="jquery-3.1.0.js"></script>
<script>
//無反應(yīng)
$(document).onclick = function(){
alert(0);
};
//Uncaught TypeError: document.click is not a function
document.click(function(){
alert(1);
});
</script>
轉(zhuǎn)換
【1】DOM轉(zhuǎn)jQuery對象
對于一個jQuery對象,只需要用$()把DOM對象包裝起來,就可以獲得一個jQuery對象
【2】jQuery轉(zhuǎn)DOM對象
jQuery是一個類數(shù)組對象,可以通過[index]或get(index)的方法得到相應(yīng)的DOM對象
console.log(document === $(document)[0]);//true console.log(document === $(document).get(0));//true
共存
如果jQuery對象和DOM對象指向同一對象,綁定不同函數(shù),則函數(shù)會按照順序依次執(zhí)行
//先彈出0,再彈出1
document.onclick = function(){
alert(0);
}
$(document).click(function(){
alert(1);
});
以上所述是小編給大家介紹的jQuery對象$.html,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
jQuery ajax請求struts action實(shí)現(xiàn)異步刷新
這篇文章主要為大家詳細(xì)介紹了JQuery ajax請求struts action實(shí)現(xiàn)異步刷新,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
jQuery實(shí)現(xiàn)點(diǎn)擊水紋波動動畫
今天要為大家紹一款由jquery實(shí)現(xiàn)的鼠標(biāo)單擊出現(xiàn)水波特效。用鼠標(biāo)點(diǎn)擊頁面,你可以看到頁面不斷出面水波紋效果。然后水波紋漸漸消失。效果非常不錯2016-04-04

