【问题标题】:jquery replace tag with tag text [duplicate]jquery用标签文本替换标签[重复]
【发布时间】:2011-06-30 14:52:43
【问题描述】:

我想用实际的 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 已完成。

【问题讨论】:

  • “实际 Html”是什么意思?只要.textReplace 没有定义,您的 html 就已经输出了您想要的输出。

标签: jquery tags replace


【解决方案1】:

知道了。

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

【讨论】:

    【解决方案2】:

    你的意思是这样的:

    $('span.textReplace').html("actual html");
    

    这个新的 HTML 源代码来自哪里?

    【讨论】:

      猜你喜欢
      • 2013-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 2011-05-22
      • 2023-04-04
      • 2019-12-08
      • 1970-01-01
      相关资源
      最近更新 更多