jQuery的replaceWith()和html()有什么区别? [英] What's the difference between jQuery's replaceWith() and html()?
本文介绍了jQuery的replaceWith()和html()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当将HTML作为参数传递时,jQuery的replaceWith()和html()函数之间有什么区别?
What's the difference between jQuery's replaceWith() and html() functions when HTML is being passed in as the parameter?
推荐答案
采用以下HTML代码:
Take this HTML code:
<div id="mydiv">Hello World</div>
正在做
$('#mydiv').html('Aloha World');
将导致:
<div id="mydiv">Aloha World</div>
正在做
$('#mydiv').replaceWith('Aloha World');
将导致:
Aloha World
因此 html()替换了元素的内容,而 replaceWith()替换了实际元素.
So html() replaces the contents of the element, while replaceWith() replaces the actual element.
这篇关于jQuery的replaceWith()和html()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文