亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 145
粉絲 7
評(píng)論 7
訪問(wèn)量 198607
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
JQuery實(shí)戰(zhàn):DOM操作和Ajax請(qǐng)求(跨域請(qǐng)求)
李東亞1??3????12?
原創(chuàng)
1044人瀏覽過(guò)

DOM操作(Jquery):

1、DOM操作插入:
(1)函數(shù)方法

方法 作用說(shuō)明
.append .appendTo 當(dāng)前元素有子元素則在子元素末尾插入,無(wú)子元素則在當(dāng)前元素后面插入 ;兩個(gè)方法作用相同,只是使用方法不同
.prepend() .prepednTo() 在元素內(nèi)部頭部插入,兩個(gè)方法作用相同,用辦法不同
.after() .insertAfter() 在元素之后插入,兩個(gè)方法作用相同,只是使用方法不同
.before() .insertBefore() 在元素之前插入,兩個(gè)方法作用相同,只是使用方法不同

2.元素的刪除操作

方法 作用說(shuō)明
.remove() 移除元素本身
.empty() 移除元素本身的內(nèi)容(包含里面的html內(nèi)容)

3.替換元素

方法 作用說(shuō)明
new.replaceAll(old) 替換元素內(nèi)所有匹配的
old.replaceWith(new) 用提供的內(nèi)容替換集合中所有匹配的元素并且返回被刪除元素的集合。

4.實(shí)操演練
(1)代碼部分

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Jquery操作和請(qǐng)求</title>
  6. <script src="jquery.js"></script>
  7. <style>
  8. ul:first-of-type{
  9. background-color: lightblue;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <ul>
  15. <li>item1</li>
  16. <li class="shuang">item2</li>
  17. <li>item3</li>
  18. <li class="shuang">item4</li>
  19. <li class="dan">item5</li>
  20. </ul>
  21. <ul>
  22. <li>item1</li>
  23. <li>item2</li>
  24. <li>item3</li>
  25. </ul>
  26. </body>
  27. <script>
  28. let cl=console.log;
  29. cl($);
  30. // appendTo和append作用相同:在元素內(nèi)部末尾(或者元素后面)插入,用法不同而已
  31. $("ul:first-child").append("<li>item6</li>");
  32. $("<li>item7</li>").appendTo($("ul:first-child"));
  33. $("ul:first-child > li:nth-child(3)").append("<li>item</li>");
  34. //在元素內(nèi)部頭部插入,兩個(gè)方法作用相同知識(shí)用辦法不同,
  35. $("ul:first-child").prepend("<li>item0</li>");
  36. $("<li>item-1</li>").prependTo($("ul:first-child"));
  37. // after()和before()
  38. $("ul:first-child").after("<h2>結(jié)束</h2>");
  39. $("ul:first-child").before("<h1>開(kāi)始</h1>");
  40. // cl($("ul:last-of-type"));
  41. $("<h2>second<h2>").insertAfter($("ul:last-of-type"));
  42. $("<h2>one<h2>").insertBefore($("ul:last-of-type"));
  43. cl($("ul:last-of-type").text());
  44. cl($("ul:last-of-type > li:last-of-type").text());
  45. // cl($("ul:nth-child(1)"));
  46. // .remove();
  47. $("li:last-of-type").remove();
  48. $("ul:last-of-type > li:nth-of-type(1)").empty();
  49. $("ul:last-of-type").empty();
  50. $("ul:last-of-type").remove();
  51. cl($(".shuang"));
  52. // 兩個(gè)函數(shù)作用相同知識(shí)用法不同
  53. $("<li>$$$$$$$$</li>").replaceAll($(".shuang"))
  54. $(".dan").replaceWith($("<li>22222</li>"));
  55. </script>
  56. </html>

Jquery請(qǐng)求和跨域請(qǐng)求

1.GET和POST請(qǐng)求:

  • $.get(url,callback());GET請(qǐng)求
  • $.post(url,data,callback());POST請(qǐng)求

2.ajax請(qǐng)求

  1. $.ajax({
  2. type:"GET",
  3. url:"url",
  4. data:{
  5. id:2,
  6. },
  7. dataType:"json|html",
  8. //告訴跨域訪問(wèn)的服務(wù)器需要返回的函數(shù)名稱(chēng)
  9. //dataType:"jsonp",
  10. //jsonpCallback: "show",
  11. success:function(){……}
  12. })
批改老師:天蓬老師天蓬老師

批改狀態(tài):合格

老師批語(yǔ):很多地方代碼不應(yīng)該省呀,現(xiàn)在你在學(xué)習(xí)階段,這樣做不好
本博文版權(quán)歸博主所有,轉(zhuǎn)載請(qǐng)注明地址!如有侵權(quán)、違法,請(qǐng)聯(lián)系admin@php.cn舉報(bào)處理!
全部評(píng)論 文明上網(wǎng)理性發(fā)言,請(qǐng)遵守新聞評(píng)論服務(wù)協(xié)議
0條評(píng)論
關(guān)于我們 免責(zé)申明 意見(jiàn)反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長(zhǎng)!
關(guān)注服務(wù)號(hào) 技術(shù)交流群
PHP中文網(wǎng)訂閱號(hào)
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時(shí)隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號(hào)
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學(xué)習(xí)!
    全站2000+教程免費(fèi)學(xué)