无法通过jQuery更改按钮文本

时间:2017-02-22 15:42:51

标签: javascript jquery html squarespace

Probaby对你来说是一个非常简单的问题jQuery向导,但我没有设法通过jQuery更改按钮的innerHTML。我有以下Squarespace页面:https://hethuisvandelingerie.squarespace.com/badmode/BM001

我想要做的是将“添加到购物车”按钮中的文本从英语更改为荷兰语。该按钮具有以下HTML结构:

<div class="sqs-add-to-cart-button-wrapper" id="yui_3_17_2_1_1487777852612_138" style="visibility: visible;">
    <div class="sqs-add-to-cart-button sqs-suppress-edit-mode sqs-editable-button " data-collection-id="5890a2ff2e69cf43f9dad6c5" data-item-id="589f1443c0302664f13c7656" data-original-label="Add To Cart" id="yui_3_17_2_1_1487777852612_146">
        <div class="sqs-add-to-cart-button-inner">Add To Cart</div>
    </div>
</div>

我使用以下jQuery脚本来更改按钮中的文本。我添加了代码的第一部分,以查看我的jQuery(我已将其链接到其他地方的API)工作。给出了“是的”警报,所以这不是问题。但是,按钮文本似乎没有改变:(。

<script>
    window.onload = function() {
      if (window.jQuery) {  
        // jQuery is loaded  
        alert("Yeah!");
      } else {
        // jQuery is not loaded
        alert("Doesn't Work");
      }
    }

    $(window).load(function() {
       $(".sqs-add-to-cart-button-inner").text("Voeg toe aan mandje");
    });
</script>

jQuery guru's,请帮帮我! KR, BarrieO

1 个答案:

答案 0 :(得分:3)

在jQuery中使用$(document).ready()

$(document).ready(function() {
  $(".sqs-add-to-cart-button-inner").text("Voeg toe aan mandje");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sqs-add-to-cart-button-wrapper" id="yui_3_17_2_1_1487777852612_138" style="visibility: visible;">
  <div class="sqs-add-to-cart-button sqs-suppress-edit-mode sqs-editable-button " data-collection-id="5890a2ff2e69cf43f9dad6c5" data-item-id="589f1443c0302664f13c7656" data-original-label="Add To Cart" id="yui_3_17_2_1_1487777852612_146">
    <div class="sqs-add-to-cart-button-inner">Add To Cart</div>
  </div>
</div>