標籤: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)