Upgrade to Pro — share decks privately, control downloads, hide ads and more …

jquery.pdf

 jquery.pdf

darrenyaoyaoyao

November 13, 2020
Tweet

More Decks by darrenyaoyaoyao

Other Decks in Programming

Transcript

  1. JQuery 起⼿式 $(function(){ // jQuery methods go here... }); $(this).hide()

    - hides the current element. $("p").hide() - hides all <p> elements. $(".test").hide() - hides all elements with class="test". $("#test").hide() - hides the element with id="test".
  2. 選擇器 <h2>This is a heading</h2> <p>This is a paragraph.</p> <button>Click

    me to hide paragraphs</ button> $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); }); $(“p”) 選擇 p 元素 $(“.class”) 選擇 class $(“#id”) 選擇 id
  3. Hide, Show <button>Hide</button> <p>This is a paragraph with little content.</p>

    <p>This is another small paragraph.</p> $(document).ready(function(){ $("button").click(function(){ $("p").hide(1000); }); }); $(“p”).hide
 $(“p”).show
 $(“p”).toggle
  4. 事件 <p id="p1">Enter this paragraph.</p> $(document).ready(function(){ $("#p1").mouseenter(function(){ alert("You entered p1!");

    }); }); $(“p”).click
 $(“p”).dbclick
 $(“p”).mouseenter
 $(“p”).mouseleave
 $(“p”).mousedown
 $(“p”).mouseup
 $(“p”).hover
 $(“p”).focus
 $(“p”).blur
  5. FadeIn, FadeOut <button>Hide</button> <p>This is a paragraph with little content.</p>

    <p>This is another small paragraph.</p> $(document).ready(function(){ $("button").click(function(){ $("p").fadeOut(3000); }); }); $(“p”).fadeIn()
 $(“p”).fadeOut()
 $(“p”).fadeOut(“slow")
 $(“p”).fadeOut(3000)
 $(“p”).fadeToggle()
  6. Slide <button>Hide</button> <p>This is a paragraph with little content.</p> <p>This

    is another small paragraph.</p> $(document).ready(function(){ $("button").click(function(){ $("p").slideUp(); }); }); $(“p”).slideDown()
 $(“p”).slideUp()
 $(“p”).slideToggle()
  7. Get <button>Hide</button> <p>This is a paragraph with little content.</p> <p>This

    is another small paragraph.</p> $(document).ready(function(){ $("button").click(function(){ alert($(“p”).text()) }); }); $(“p”).text() $(“p”).html() $(“p”).val()
  8. Set <button>Hide</button> <p>This is a paragraph with little content.</p> <p>This

    is another small paragraph.</p> $(document).ready(function(){ $("button").click(function(){ $(“p”).text(“Hello”) }); }); $(“p”).text(“Hello”) $(“p”).html(“Hello”) $(“p”).val(“Hello”)
  9. Add <button>Hide</button> <p>This is a paragraph with little content.</p> <p>This

    is another small paragraph.</p> $(document).ready(function(){ $("button").click(function(){ $(“p”).append(“Hello”) }); }); $(“p”).append(“Hello”) $(“p”).prepend(“
 <p>Hello</p>
 ”) $(“p”).before(“Hello”) $(“p”).after(“Hello”)
  10. Remove <button>Hide</button> <p>This is a paragraph with little content.</p> <p>This

    is another small paragraph.</p> $(document).ready(function(){ $("button").click(function(){ $(“p”).remove() }); }); $(“p”).remove() $(“p”).empty()
  11. CSS Class <button>Hide</button> <p>This is a paragraph with little content.</p>

    <p>This is another small paragraph.</p> $(document).ready(function(){ $("button").click(function(){ $(“p”).addClass(“blue”) }); }); $(“p”).addClass(“blue”) $(“p”).removeClass(“blue”)
  12. CSS <button>Hide</button> <p>This is a paragraph with little content.</p> <p>This

    is another small paragraph.</p> $(document).ready(function(){ $("button").click(function(){ $(“p”).css(“color”, “blue”) }); }); $(“p”).css(“color”,“blue”)
  13. Javascript String 函數 <p id="demo"></p> var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var

    sln = txt.length; document.getElementById(“demo"). innerHTML = sln 26
  14. Javascript Array <p id="demo"></p> var list = [‘A’, ‘B’, ‘C’]

    document.getElementById(“demo"). innerHTML = list[0] ABC