【问题标题】:jQuery Text ReplacejQuery 文本替换
【发布时间】:2011-09-11 11:16:12
【问题描述】:

有一些文本需要替换,在这个网站上搜索了所有标题相似但没有运气的结果。

目前的文字是手续费:我需要它说运输保险:-请帮忙!

这是页面的html输出;

<div class="c3 right">       
    <h2>Order Summary</h2>
    <table class="styledtable">
        <thead>
        <tr>
            <th>Quantity</th>

            <th>Product</th>
            <th>Price</th>
            <th>Total</th>
        </tr>
        </thead>
        <tbody>

                <tr>

                    <td style="text-align:center">1</td>
                    <td><strong>ACT Clutch Kit - Heavy Duty (HD) (DC1-HDSS)</strong>
<div class="order_item_notes">HD Clutch Kit<br/> Performance Street Disc (SS)</div>
<div class="order_item_specs">
Components : D018, 3001532, ATCP23<br/>
</div>
 </td>
                    <td style="text-align:right">$314.25</td>

                    <td style="text-align:right">$314.25</td>
                </tr>


        <tr>
            <td colspan="3" style="text-align:right">Items Total</td>
            <td style="text-align:right">$<span id="itemstotal">314.25</span></td>
        </tr>
        <tr>

            <td colspan="3" style="text-align:right">Shipping:</td>
            <td style="text-align:right">$<span id="shippingtotal">TBD</span></td>
        </tr>

        <tr>
            <td colspan="3" style="text-align:right">Handling Fee:</td>
            <td style="text-align:right">$<span id="handlingfee">0.00</span></td>

        </tr>

        <tr>
            <td colspan="3" style="text-align:right">Tax:</td>
            <td style="text-align:right">$<span id="taxtotal">0.00</span></td>
        </tr>
        <tr>
            <td colspan="3" style="text-align:right">Order Total:</td>

            <td style="text-align:right">$<span id="total">0.00</span></td>
        </tr>
        </tbody>            
    </table>

    <p>Upon checkout, you <strong>must enter</strong> your cars <strong>year, make and model</strong> into the comments section at the bottom of this page.&nbsp;<strong> We will not complete your order if we do not have this information!</strong></p>

<p>&nbsp;</p>
</div>
</div> 

【问题讨论】:

    标签: javascript jquery html text replace


    【解决方案1】:

    您可以使用 jQuery :contains 选择器:

    $("td:contains('Handling Fee:')").text("Shipping Insurance:");
    

    你可以在这里看到它的实际效果:http://jsfiddle.net/cnhYj/

    更新

    为了在文档准备好后让它工作,你可以这样写:

    $(function() {
        $("td:contains('Handling Fee:')").text("Shipping Insurance:");
    });
    

    【讨论】:

    • 您好 Variant,感谢您的解决方案,但是,我无法让它工作。我在标题中添加了以下内容; 我是否正确地处理了这个问题?
    • 非常感谢 Variant。感谢您的帮助。
    【解决方案2】:
    $("td:contains('Handling Fee:').text('Shipping Insurance');
    

    【讨论】:

      【解决方案3】:

      我没有看到任何 javascript 只是 html

      你想把这个.. <td colspan="3" style="text-align:right">Handling Fee:</td>

      进入这个... <td colspan="3" style="text-align:right">Shipping Insurance:</td>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-14
        • 2015-06-06
        • 2014-05-24
        • 1970-01-01
        • 2014-08-15
        • 2011-02-02
        • 2012-02-07
        • 1970-01-01
        相关资源
        最近更新 更多