当前位置: 代码迷 >> Web前端 >> jQuery源码浅谈系列-replaceWith()
  详细解决方案

jQuery源码浅谈系列-replaceWith()

热度:72   发布时间:2012-07-26 12:01:08.0
jQuery源码浅谈系列---replaceWith()

replaceWith(cpntent) ? ?

?

@参数 content ?----String,Element,jQuery,Function

?

?? 用于将匹配元素替换掉的内容。如果这里传递一个函数进来,返回值必须是HTML字符串。

?

@example1 新的参数内容替换匹配已有的内容

?

?

<p>Hello</p>

?

?

$("p").replaceWith("<b>test</b>");

//结果
<b>test</b>

?

@example2 两个内容都存在的情况:

?

?

<div class="box">
   <div class="first">1</div>
   <div class="second">2</div>
   <div class="third">3</div>
</div>

?

?? 用第一段来替换第3段?

?

?

$('.third').replaceWith($('.first'));

?

??结果

?

?

<div class="box">
  <div class="second">2</div>
  <div class="first">1</div>
</div>
  相关解决方案