jQuery常用API

  • 準備

所有jQuery方法都是由$開始的,通常稱作為 美元符號,或者簡稱為bling。

語法如下
<script>
$(document).ready(function(){

});
</script>
  • jQuery 使用選擇器獲取HTML元素

jQuery通過選擇器來選擇一個元素的,然后操作元素做些改變。

添加按鈕回彈效果
$("button")來選中按鈕
用.addClass("animated bounce")給按鈕加CSS class。

<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
});
</script>
  • jQuery使用addClass()方法給元素加class

    • $(".well").addClass("animated shake");
  • jQuery根據(jù)id屬性來獲取元素

    • 漸變隱藏效果
    • $("#target3").addClass("animated fadeOut");
  • 三種選擇器

    • 元素選擇器:$("button")
    • class選擇器:$(".btn")
    • id選擇器:$("#target1")
  • 使用jQUery刪除HTML元素的class

    • $("#target2").removeClass("btn-default");
  • 使用jQUery改變HTML元素的css樣式

    • 選擇器.css("屬性","值");
    • $("#target1").css("color","red");
  • 使用jQUery設(shè)置元素不可用

    • $("#target1").prop("disabled",true);
  • jQuery使用text()改變文本內(nèi)容

    • <em></em>[emphasize]標簽來重寫和強調(diào)標題文本
    • .text() 它只能改變文本但不能修改標記
    • $("#target4").html("<em>#target4</em>");
  • 使用jQuery刪除一個html元素

    • $(#target4).remove();
  • jQuery使用appendTo()移動html元素

    • 把元素從一個div里移到另外一個div里
    • $("#target2").appendTo("#right-well");
  • jQuery使用clone()方法拷貝元素

    • 移動元素就是剪切,拷貝元素就是復制,所以應(yīng)該就是clone一個,然后移動過去。
    • $("#target5").clone().appendTo("#left-well");
  • jQuery使用parent()操作父級元素

    • $("#target1").parent().css("background-color","red");
  • jQuery使用children()操作子級元素

    • $("#right-well").children().css("color","orange");
  • jQuery使用target:nth-child(n) CSS選擇器索引操作元素

    • :nth-child()按照順序索引是從1開始的
    • $(".target:nth-child(2)").addClass("animated bounce");
  • jQuery使用選擇器操作j索引元素

    • jQuery里的索引是從0開始的
    • $(".target:even").addClass("animated shake");
    • $(".target:odd").addClass("animated shake");
  • 使用jQuery修改整個頁面

    • $("body").addClass("animated hinge");
    • $("body").addClass("animated fadeOut");
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容