Javascript jQuery在控制台中工作,但当我将其保存在我的站点中时,它就不工作了';T

Javascript jQuery在控制台中工作,但当我将其保存在我的站点中时,它就不工作了';T,javascript,jquery,wordpress,woocommerce,checkout,Javascript,Jquery,Wordpress,Woocommerce,Checkout,创建此jQuery是为了在我的wordpress站点中添加额外价格: jQuery(document).ready( function(){ var totprice = jQuery(".order-total .woocommerce-Price-amount.amount").text().replace('$','').replace(',',''); var leaseprice = (Number(totprice)) * (0.0198);

创建此jQuery是为了在我的wordpress站点中添加额外价格:

jQuery(document).ready( function(){
    var totprice = jQuery(".order-total .woocommerce-Price-amount.amount").text().replace('$','').replace(',','');
    var leaseprice = (Number(totprice)) * (0.0198);
    jQuery(".woocommerce-checkout-review-order-table tbody").append("<tr class='lp-total'><td class='lp-text'>Estimated Commercial Lease Total: </td>" + "<td class='lp-price'>" + "$" + leaseprice.toFixed(1) + "</td>"+ "</tr>");
});
jQuery(文档).ready(函数(){
var totprice=jQuery(“.order total.woocommerce Price amount.amount”).text().replace(“$”,“).replace(“,”,”);
var leaseprice=(数字(总价))*(0.0198);
jQuery(“.woocommerce checkout review order table tbody”).append(“预计商业租赁总额:“+”+“$”+租赁价格.toFixed(1)++”+);
});
html:

<table class="shop_table woocommerce-checkout-review-order-table">
    <thead>
        <tr>
            <th class="product-name">Product</th>
            <th class="product-total">Subtotal</th>
        </tr>
    </thead>
    <tbody>
        <tr class="cart_item">
            <td class="product-name"> Max-EV 20&nbsp; <strong class="product-quantity">×&nbsp;1</strong> </td>
            <td class="product-total"> <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>30,950.00</span>
            </td>
        </tr>
    </tbody>
    <tfoot>
        <tr class="cart-subtotal">
            <th>Subtotal</th>
            <td><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>30,950.00</span>
            </td>
        </tr>
        <tr class="order-total">
            <th>Total</th>
            <td><strong><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>30,950.00</span></strong> </td>
        </tr>
    </tfoot>
</table>

产品
小计
最大EV 20×1
$30,950.00
小计
$30,950.00
全部的
30950.00美元
它在控制台中工作正常,但只要我将其保存在custom.js文件中并按下刷新按钮检查它是否工作,我就会在jQuery中看到html,然后它会自动隐藏

请注意,如果我将html附加到同一页面上的任何其他位置,它都可以正常工作。但在这里,我试图将它附加到一个标记中,当我这样做时,就会出现这个问题


jQuery代码中是否有错误?

您是否将jQuery包含到JS中

var script = document.createElement('script');
script.src = '//code.jquery.com/jquery-3.4.1.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);

同时尝试清除缓存。

是,包括jQuery。如果我将html附加到站点中的任何其他位置,它都可以正常工作。但在这里,我试图将其附加到标记中。