簡體   English   中英

從ajax返回的jQuery不起作用

[英]Returned jquery from ajax not working

所以我有2個單選按鈕,應該可以更改頁面中的一行。

要更改的行的代碼是:

<span id='checkout_total' class="pricedisplay checkout-total">
<span class='pricedisplay'>&#036;13.00</span></span>

當單擊單選按鈕時,我有一個ajax請求返回以下內容:

jQuery('.pricedisplay.checkout-total').html("<span class='pricedisplay'>&#036;16.00</span>");

所以現在span class ='pricedisplay'應該顯示16.00而不是13.00

問題是,它沒有在頁面中更改。.仍然顯示13.00。

如果我在chrome中使用開發工具並將jquery行粘貼到控制台中,則它會正確更改

您的選擇器應為#checkout_total.checkout_total不能使用.pricedisplay因為兩個跨度都具有相同的類,並且您正在替換<span id='checkout_total' class="pricedisplay checkout-total">內的span元素

 $(function(){  //just incase if you missed this
    jQuery('#checkout_total').html("<span class='pricedisplay'>&#036;16.00</span>");
 });

因為您在該元素中提到了ID,所以我將使用jQuery('#checkout_total')

如果您只需要更改跨度內的文本,則可以使用

jQuery('#checkout_total .pricedisplay').text("&#036;16.00");

試試看(代碼更淺)

jQuery('#checkout_total .pricedisplay').html("&#036;16.00");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM