日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

6月8號工作(jQuery

 一夜梨花開 2014-07-30
今天的工作

1、append() 方法

Html5代碼 復(fù)制代碼 收藏代碼
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">  
  5. </script>  
  6. <script>  
  7. $(document).ready(function(){  
  8.   $("#btn1").click(function(){  
  9.     $("p").append(" <b>Appended text</b>.");  
  10.   });  
  11.   
  12.   $("#btn2").click(function(){  
  13.     $("ol").append("<li>Appended item</li>");  
  14.   });  
  15. });  
  16. </script>  
  17. </head>  
  18.   
  19. <body>  
  20. <p>This is a paragraph.</p>  
  21. <p>This is another paragraph.</p>  
  22. <ol>  
  23. <li>List item 1</li>  
  24. <li>List item 2</li>  
  25. <li>List item 3</li>  
  26. </ol>  
  27. <button id="btn1">追加文本</button>  
  28. <button id="btn2">追加列表項</button>  
  29. </body>  
  30. </html>  


append() 方法可以將原本沒有的html通過jquery加進去只要使用和前面同樣的class就可以在添加的瞬間完成style的設(shè)置

2、prepend() 方法

Html5代碼 復(fù)制代碼 收藏代碼
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  
  5. <script>  
  6. $(document).ready(function(){  
  7.   $("#btn1").click(function(){  
  8.     $("p").prepend("<b>Prepended text</b>. ");  
  9.   });  
  10.   $("#btn2").click(function(){  
  11.     $("ol").prepend("<li>Prepended item</li>");  
  12.   });  
  13. });  
  14. </script>  
  15. </head>  
  16. <body>  
  17.   
  18. <p>This is a paragraph.</p>  
  19. <p>This is another paragraph.</p>  
  20. <ol>  
  21. <li>List item 1</li>  
  22. <li>List item 2</li>  
  23. <li>List item 3</li>  
  24. </ol>  
  25.   
  26. <button id="btn1">添加文本</button>  
  27. <button id="btn2">添加列表項</button>  
  28.   
  29. </body>  
  30. </html>  


prepend() 方法跟前面的元素添加是一樣的效果但是一樣的在于在面的方法是在默認的到最后進行添加但是prepend() 方法是可以在最前面開始進行添加

3、remove() 方法

Html5代碼 復(fù)制代碼 收藏代碼
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  
  5. <script>  
  6. $(document).ready(function(){  
  7.   $("button").click(function(){  
  8.     $("#div1").remove();  
  9.   });  
  10. });  
  11. </script>  
  12. </head>  
  13.   
  14. <body>  
  15.   
  16. <div id="div1" style="height:100px;width:300px;border:1px solid black;background-color:yellow;">  
  17. This is some text in the div.  
  18. <p>This is a paragraph in the div.</p>  
  19. <p>This is another paragraph in the div.</p>  
  20. </div>  
  21.   
  22. <br>  
  23. <button>刪除 div 元素</button>  
  24.   
  25. </body>  
  26. </html>  


remove() 方法可以把指定的元素通過remove() 方法給刪除掉在那里面就是把整個div給全部刪除掉

4、empty() 方法

Html5代碼 復(fù)制代碼 收藏代碼
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  
  5. <script>  
  6. $(document).ready(function(){  
  7.   $("button").click(function(){  
  8.     $("#div1").empty();  
  9.   });  
  10. });  
  11. </script>  
  12. </head>  
  13.   
  14. <body>  
  15.   
  16. <div id="div1" style="height:100px;width:300px;border:1px solid black;background-color:yellow;">  
  17. This is some text in the div.  
  18. <p>This is a paragraph in the div.</p>  
  19. <p>This is another paragraph in the div.</p>  
  20. </div>  
  21.   
  22. <br>  
  23. <button>清空 div 元素</button>  
  24.   
  25. </body>  
  26. </html>  


empty() 方法同樣是刪除但是不一樣的事前者是全部刪除連div自身一起刪除但是empty() 方法不一樣empty() 方法是清空意思就是可以把指定的div里面的內(nèi)容全部清空但是會保留下當前的div

5、addClass() 方法

Html5代碼 復(fù)制代碼 收藏代碼
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">  
  5. </script>  
  6. <script>  
  7. $(document).ready(function(){  
  8.   $("button").click(function(){  
  9.     $("#div1").addClass("important blue");  
  10.   });  
  11. });  
  12. </script>  
  13. <style type="text/css">  
  14. .important  
  15. {  
  16. font-weight:bold;  
  17. font-size:xx-large;  
  18. }  
  19. .blue  
  20. {  
  21. color:blue;  
  22. }  
  23. </style>  
  24. </head>  
  25. <body>  
  26.   
  27. <div id="div1">這是一些文本。</div>  
  28. <div id="div2">這是一些文本。</div>  
  29. <br>  
  30. <button>向第一個 div 元素添加類</button>  
  31.   
  32. </body>  
  33. </html>  


addClass() 方法是可以通過jquery直接向一個沒有class的標簽里面添加進入一個帶有屬性的class在里面在點擊按鈕以后原來的第二行文字會發(fā)生變化對應(yīng)$("#div1").addClass("important blue");這條語句的意思是變成藍色加大

6、removeClass() 方法

Html5代碼 復(fù)制代碼 收藏代碼
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  
  5. <script>  
  6. $(document).ready(function(){  
  7.   $("button").click(function(){  
  8.     $("h1,h2,p").removeClass("blue");  
  9.   });  
  10. });  
  11. </script>  
  12. <style type="text/css">  
  13. .important  
  14. {  
  15. font-weight:bold;  
  16. font-size:xx-large;  
  17. }  
  18. .blue  
  19. {  
  20. color:blue;  
  21. }  
  22. </style>  
  23. </head>  
  24. <body>  
  25.   
  26. <h1 class="blue">標題 1</h1>  
  27. <h2 class="blue">標題 2</h2>  
  28. <p class="blue">這是一個段落。</p>  
  29. <p>這是另一個段落。</p>  
  30. <br>  
  31. <button>從元素上刪除類</button>  
  32. </body>  
  33. </html>  


removeClass() 方法是可以將原本字體的藍色給刪除掉不是改變是刪除掉

7、toggleClass() 方法

Html5代碼 復(fù)制代碼 收藏代碼
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">  
  5. </script>  
  6. <script>  
  7. $(document).ready(function(){  
  8.   $("button").click(function(){  
  9.     $("h1,h2,p").toggleClass("blue");  
  10.   });  
  11. });  
  12. </script>  
  13. <style type="text/css">  
  14. .blue  
  15. {  
  16. color:blue;  
  17. }  
  18. </style>  
  19. </head>  
  20. <body>  
  21.   
  22. <h1>標題 1</h1>  
  23. <h2>標題 2</h2>  
  24. <p>這是一個段落。</p>  
  25. <p>這是另一個段落。</p>  
  26. <button>切換 CSS 類</button>  
  27. </body>  
  28. </html>  


toggleClass() 方法有著上面兩種效果在沒有藍色的字體上加上藍色在有藍色的字體上清除藍色

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約