開始學習jQuery和準備工做

<script>
$(document).ready(function(){

});css

首先,在頁面頂部添加一行script元素,而後在下一行寫上結束符。html

瀏覽器會運行script裏全部的Javascript,包括jQuery。瀏覽器

在你的script元素裏,添加這段代碼:$(document).ready(function() {到你的script中,而後在下一行用});結束它。app


使用jQuery選擇器操做同一元素

<script>
$(document).ready(function() {
$("button").addClass("animated");
$(".btn").addClass("shake");
$("#target1").addClass("btn-primary");//首選項
});
</script>spa

使用jQuery改變HTML元素的CSS樣式

$("#target1").css("color", "blue");code

使用jQuery設置元素不可用

$("button").prop("disabled", true);htm

使用jQuery改變元素中的文本

$("h3").html("<em>jQuery Playground</em>");索引

使用jQuery刪除一個HTML元素

 $("#target4").remove();ip

jQuery使用appendTo()移動HTML元素

$("#target4").appendTo("#left-well");rem

jQuery使用clone()方法複製元素

$("#target2").clone().appendTo("#right-well");//兩個jQuery方法合在一塊兒使用了?這種叫方法鏈function chaining

target2left-well複製到right-well

jQuery使用parent()操做父級元素

$("#left-well").parent().css("background-color", "blue")

jQuery使用children()操做子級元素

$("#left-well").children().css("color", "blue")

 

jQuery使用target:nth-child(n) CSS選擇器獲取子元素

$(".target:nth-child(3)").addClass("animated bounce");

//如下代碼顯示如何給jQuery Playground中的每一個井中(left well和right well)的第三個子元素添加bounce類:

jQuery使用選擇器操做偶數索引元素

$(".target:even").addClass("animated shake"); //偶數

$(".target:odd").addClass("animated shake");//奇數

使用jQuery修改整個頁面

$("body").addClass("animated fadeOut");//整個body有淡出效果

$("body").addClass("animated hinge");//一左上角爲圓心 順時針晃動 下墜淡出

相關文章
相關標籤/搜索