- HTML渲染完成后執(zhí)行ready function崖飘,所以最好把方法寫在這里面智亮,否則可能出錯(cuò)
$(document).ready(function(){
});
- 所有jQuery方法都是由$開(kāi)始的酌呆,通常稱作為 美元符號(hào)牌里,或者簡(jiǎn)稱為bling融柬;
jQuery通過(guò)選擇器來(lái)選擇一個(gè)元素的死嗦,然后操作元素做些改變趋距。
- 操作類
$("#target3").addClass("animated fadeOut");
- 操作css
$("#target1").css("color", "blue");
- 操作元素屬性
$("button").prop("disabled",true);
- 添加html文本
添加強(qiáng)調(diào)文本jQuery Playground
$("#target4").html("<em>jQuery Playground</em>")
- 移除元素
$("#target4").remove();
- 移動(dòng)元素到其他元素中
$("#target2").appendTo("#right-well");
- 復(fù)制元素
$("#target5").clone().appendTo("#left-well"); //復(fù)制并移動(dòng)
- 訪問(wèn)父元素
$("#target1").parent().css("background-color","red");
- 訪問(wèn)子元素
$("#right-well").children().css("color","orange");
- 根據(jù)索引訪問(wèn)子元素 $("
.targetClass
:nth-child(n
)")
$(".target:nth-child(2)").addClass("animated bounce");//訪問(wèn)target類下的第二個(gè)子元素
- 訪問(wèn)索引為奇
$(".target:odd")
,偶數(shù)$(".target:even")
的所有元素
$(".target:even").addClass("animated shake");
$(".target:odd").addClass("animated bounce");
- 結(jié)尾插入內(nèi)容
$("#target2").append("拼接字符串");
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者