gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:40:26 25 4
gpt4 key购买 nike

当 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()替换实际元素。

关于jquery - jQuery的replaceWith()和html()有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33876045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com