区别在于,html()会替换指定元素内部的HTML,而replaceWith()会替换元素本身及其内部的HTML。


例子:

1
<div id="myid" />


1
2
3
4
5
// <div ><p>Text</p></div>
$('#myid').html('<p>Text</p>');
 
// <p>Text</p>
$('#myid').replaceWith('<p>Text</p>');
 




相关文章:

  • 2021-11-21
  • 2021-12-24
  • 2022-12-23
  • 2021-12-15
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
猜你喜欢
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2021-08-23
  • 2022-02-09
  • 2021-04-01
相关资源
相似解决方案