jquery中的replaceWith()和html()有什么区别?

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


例子:

1
<div id="myid" />


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




一切为了梦想!
原文地址:https://www.cnblogs.com/wenqd/p/2c995647da55a2f33be10883b66a66ef.html