将HTML作为参数传递时,jQuery的replaceWith()和html()函数之间有什么区别?
采取以下HTML代码:
<div id="mydiv">Hello World</div>
正在做:
$('#mydiv').html('Aloha World');
将导致:
<div id="mydiv">Aloha World</div>
正在做:
$('#mydiv').replaceWith('Aloha World');
将导致:
Aloha World
因此html()替换了元素的内容,而replaceWith()替换了实际的元素。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句