欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

深入淺析jQuery對(duì)象$.html

 更新時(shí)間:2016年08月22日 13:39:56   作者:小火柴的藍(lán)色理想  
這篇文章主要介紹了jQuery對(duì)象$.html的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

$對(duì)象

  說(shuō)起jQuery,最明顯的標(biāo)志,毫無(wú)疑問(wèn),就是, ,其實(shí)是jquery的簡(jiǎn)寫(xiě)。而使用$()包裝的對(duì)象就是jQuery對(duì)象

  與jQuery對(duì)象相對(duì)應(yīng)的就是DOM對(duì)象,DOM對(duì)象其實(shí)就是DOM元素節(jié)點(diǎn)對(duì)象

  如果直接寫(xiě)document,則指的是document的DOM元素對(duì)象

document.onclick = function(){
alert('dom');
}

  而如果用()包括起來(lái),如 ()包括起來(lái),如(document),是jQuery(document)的簡(jiǎn)寫(xiě)形式,則指的是jQuery對(duì)象

<script src="jquery-3.1.0.js"></script> 
<script>
console.log(jQuery(document));//[document]
console.log($(document));//[document]
console.log(document);//#document
</script>

  [注意]jQuery對(duì)象無(wú)法使用DOM對(duì)象的方法,DOM對(duì)象也無(wú)法使用jQuery對(duì)象的方法

<script src="jquery-3.1.0.js"></script> 
<script>
//無(wú)反應(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對(duì)象

  對(duì)于一個(gè)jQuery對(duì)象,只需要用$()把DOM對(duì)象包裝起來(lái),就可以獲得一個(gè)jQuery對(duì)象

【2】jQuery轉(zhuǎn)DOM對(duì)象

  jQuery是一個(gè)類(lèi)數(shù)組對(duì)象,可以通過(guò)[index]或get(index)的方法得到相應(yīng)的DOM對(duì)象

console.log(document === $(document)[0]);//true
console.log(document === $(document).get(0));//true

 共存

  如果jQuery對(duì)象和DOM對(duì)象指向同一對(duì)象,綁定不同函數(shù),則函數(shù)會(huì)按照順序依次執(zhí)行

//先彈出0,再?gòu)棾?
document.onclick = function(){
alert(0);
}
$(document).click(function(){
alert(1);
});

以上所述是小編給大家介紹的jQuery對(duì)象$.html,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論