我正在使用一个 wordpress 插件,它会吐出如下所示的代码:
<div class=" product-addon product-addon-extra-tip">
<p class="form-row form-row-wide addon-wrap-2004-extra-tip-0-0">
<label>
<input type="radio" class="addon addon-radio" name="addon-2004-extra-tip-0[]" data-raw-price="2" data-price="2" value="2"> $2 (<span class="amount">$2.00</span>)</label>
</p>
<p class="form-row form-row-wide addon-wrap-2004-extra-tip-0-1">
<label>
<input type="radio" class="addon addon-radio" name="addon-2004-extra-tip-0[]" data-raw-price="5" data-price="5" value="5"> $5 (<span class="amount">$5.00</span>)</label>
</p>
</div>
您可以看到<span>
包含带小数的美元值。我想从每个实例中修剪小数点和尾随零。
我知道这应该可以使用toFixed()
,但我无法弄清楚到底如何只针对那些特定<span>
的 s。我不能简单地通过类名来选择,amount
因为它在其他地方使用。
所以,我需要在 with class 中定位s <span>
with class 。我需要从这些s 中的字符串中删除小数。amount
<div>
product-addon
<span>