【问题标题】:jQuery table replace partial table content inside htmljQuery表格替换html中的部分表格内容
【发布时间】:2017-10-04 05:35:44
【问题描述】:

我有这张桌子:

HTML

<div class="BBclass1 BBclass2">
    <table>
        <tr>
            <td><b>name:</b> value1</td>
            <td>Value2</td>
            <td>Value3</td>
            <td>Value4</td>
        </tr>
    </table>
<div>

我需要将'name:' 替换为 'Hello:'

我该怎么做?

我已经试过了

$("td :contains('name:')").text("Hello:"); 

由于某种原因,它用 name1 替换了整个表。

这也不起作用:

$("div:contains('name:')").html("Hello");

还有其他建议吗?

【问题讨论】:

    标签: jquery html replace html-table cell


    【解决方案1】:

    你是using the wrong selector.

    之间不能有空格

    `"td :contains"`
        ^------- Remove this space
    

    应该是

    $("td:contains('name:')").text("Hello:"); 
    

    你也可以试试

    $("td b:contains('name:')").text("Hello:"); 
    

    Check Fiddle

    【讨论】:

    • 很高兴有帮助:)
    猜你喜欢
    • 2020-07-11
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    • 2010-10-16
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    相关资源
    最近更新 更多