jQuery 學習筆記(TryjQuery)

來源:互聯網
上載者:User

標籤:des   style   color   os   使用   io   strong   for   ar   

第一集.
頁面載入完成後執行 js 代碼: 

$(document).ready(function(){

  $("h1").text("Where to?");

});

 

第二集.
尋找網頁元素的方式:

$("h1") 使用標籤擷取網頁元素

$("#ID") 使用標籤ID擷取網頁元素

$(".ClassName") 使用標籤類名擷取網頁元素

CSS

p { ... }
#container { ... }
.articles { ... }


jQuery

$("p");
$("#container");
$(".articles");

 

第三集.
擷取網頁元素中的子項目和多種方式擷取網頁元素的集合:

$("#destinations li"); 擷取 id 為 destinations 的網頁元素中包含的所有標籤為 li 的元素,包含兒子、孫子、子孫萬代...。

$("#destinations > li"); 擷取 id 為 destinations 的網頁元素中直屬的標籤為 li 的元素,僅包含兒子。

$(".promo, #france"); 擷取類名為 promo 或 id 為 france 的多個子項目。

$("#destinations li:first");

$("#destinations li:last");

$("#destinations li:odd");

$("#destinations li:even");

watch out, the index starts at 0

 

第四集.
使用.first() 的效率比使用偽類:first效率更高:

$("#destinations li");

$("#destinations").find("li");  //速度快

$("li:first");

$("li").first();  //速度快

$("li:last");

$("li").last();  //速度快

$("li").first().next().prev();

$("li").first().parent();

$("#destinations").children("li");

children(), unlike find(), only selects direct children

 

第五集.
把元素<element>添加到目標元素的下級的後面、下級的前面、同級的後面、同級的前面

.append(<element>)

.prepend(<element>)

.after(<element>)

.before(<element>)

 

把目標元素添加到元素<element>下級的後面、下級的前面、同級的後面、同級的前面

.appendTo(<element>)

.prependTo(<element>)

.insertTo(<element>)

.insertBefort(<element>)

 

第七集.

.closest() 從當前元素開始遍曆,沿DOM樹向上遍曆,直到找到已應用選取器的一個匹配為止,返回包含零個或一個元素的 jQuery 對象。 .parents() 從父元素開始遍曆,沿 DOM 樹向上遍曆,直到文檔的根項目為止,將每個祖先元素添加到一個臨時的集合;如果應用了選取器,則會基於該選取器對這個集合進行篩選。

 

第八集.
擷取自訂屬性的值

jQuery 學習筆記(TryjQuery)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.