gpt4 book ai didi

jquery 用标签文本替换标签

转载 作者:行者123 更新时间:2023-12-01 03:52:41 24 4
gpt4 key购买 nike

我想用实际的html替换标签span.textReplace

假设我有一个字符串 dom,如下所示:

<div id="content">
hello world <span id="query1" class="textReplace">Query 1</span><br/>this is a test <span id="query2" class="textReplace">Query 2</span> this is <b>another</b> test <span id="query3" class="textReplace">Query3</span> finished
</div>

我希望 #content 的 html 看起来像这样:

hello world Query1
这是一个测试 Query2,这是另一个测试 Query3 已完成。

最佳答案

明白了。

$("#content span.textReplace").replaceWith(function () { return $(this).text() });

关于jquery 用标签文本替换标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6536698/

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