小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

JQuery簡(jiǎn)單學(xué)習(xí)(7)——jQuery HTML 操作

 kekokeko 2011-03-01

JQuery簡(jiǎn)單學(xué)習(xí)(7)——jQuery HTML 操作

文章分類:Web前端

 

jQuery 包含很多供改變和操作 HTML 的強(qiáng)大函數(shù)。

————————————————————
改變 HTML 內(nèi)容
語(yǔ)法
Js代碼 復(fù)制代碼
  1. $(selector).html(content)  
 html() 函數(shù)改變所匹配的 HTML 元素的內(nèi)容(innerHTML)。
實(shí)例
Js代碼 復(fù)制代碼
  1. <html>   
  2. <head>   
  3. <script type="text/javascript" src="/jquery/jquery.js"></script>   
  4. <script type="text/javascript">   
  5. $(document).ready(function(){   
  6.   $("button").click(function(){   
  7.   $("p").html("W3School");   
  8.   });   
  9. });   
  10. </script>   
  11. </head>   
  12.   
  13. <body>   
  14. <h2>This is a heading</h2>   
  15. <p>This is a paragraph.</p>   
  16. <p>This is another paragraph.</p>   
  17. <button type="button">Click me</button>   
  18. </body>   
  19.   
  20. </html>  
 ————————————————————
添加 HTML 內(nèi)容
語(yǔ)法
Js代碼 復(fù)制代碼
  1. $(selector).append(content)  
 append() 函數(shù)向所匹配的 HTML 元素內(nèi)部追加內(nèi)容。

語(yǔ)法
Js代碼 復(fù)制代碼
  1. $(selector).prepend(content)  
 prepend() 函數(shù)向所匹配的 HTML 元素內(nèi)部預(yù)置(Prepend)內(nèi)容。

實(shí)例
Js代碼 復(fù)制代碼
  1. <html>   
  2. <head>   
  3. <script type="text/javascript" src="/jquery/jquery.js"></script>   
  4. <script type="text/javascript">   
  5. $(document).ready(function(){   
  6.   $("button").click(function(){   
  7.   $("p").append(" <b>W3School</b>.");   
  8.   });   
  9. });   
  10. </script>   
  11. </head>   
  12.   
  13. <body>   
  14. <h2>This is a heading</h2>   
  15. <p>This is a paragraph.</p>   
  16. <p>This is another paragraph.</p>   
  17. <button type="button">Click me</button>   
  18. </body>   
  19.   
  20. </html>  

 語(yǔ)法
Js代碼 復(fù)制代碼
  1. $(selector).after(content)  
 after() 函數(shù)在所有匹配的元素之后插入 HTML 內(nèi)容。

語(yǔ)法
Js代碼 復(fù)制代碼
  1. $(selector).before(content)  
 before() 函數(shù)在所有匹配的元素之前插入 HTML 內(nèi)容。

實(shí)例
Js代碼 復(fù)制代碼
  1. <html>   
  2. <head>   
  3. <script type="text/javascript" src="/jquery/jquery.js"></script>   
  4. <script type="text/javascript">   
  5. $(document).ready(function(){   
  6.   $("button").click(function(){   
  7.   $("p").after(" W3School.");   
  8.   });   
  9. });   
  10. </script>   
  11. </head>   
  12.   
  13. <body>   
  14. <h2>This is a heading</h2>   
  15. <p>This is a paragraph.</p>   
  16. <p>This is another paragraph.</p>   
  17. <button type="button">Click me</button>   
  18. </body>   
  19.   
  20. </html>  
 ————————————————————
jQuery HTML 操作 - 來(lái)自本頁(yè)
函數(shù)描述 $(selector).html(content) 改變被選元素的(內(nèi)部)HTML $(selector).append(content) 向被選元素的(內(nèi)部)HTML 追加內(nèi)容 $(selector).prepend(content) 向被選元素的(內(nèi)部)HTML “預(yù)置”(Prepend)內(nèi)容 $(selector).after(content) 在被選元素之后添加 HTML $(selector).before(content) 在被選元素之前添加 HTML

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

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多