jquery 替换内容

2015-01-23 21:29:11

替换内容

replaceWith()和replaceAll()方法都可以用于替换元素或元素中的内容,但它们调用时,内容和被替换元素所在的位置不同,分别为如下所示:

$(selector).replaceWith(content)和$(content).replaceAll(selector)

参数selector为被替换的元素,content为替换的内容。

 

  1. <body> 
  2.         <h3>before() after()方法在元素前后插入内容</h3> 
  3.         <span class="green">爱思资源网</span> 
  4.          
  5.         <script type="text/javascript"> 
  6.             var $htmla = "<span class='red'>Www.aseoe.Com</span>" 
  7.            var $htmlb = "<span class='red'>web前端开发</span>" 
  8.             $(".green").after($htmla); 
  9.              $(".green").before($htmlb); 
  10.         </script> 
  11.     </body> 
  12. </html> 

jquery 替换内容
 


为您推荐