Woocommerce 如何使用 jquery 获取 "cart-subtotal" 中的值
Woocommerce how to use jquery to get a value inside "cart-subtotal"
这个问题已经提出,但我需要一些不同的东西,我不知道它是否可能。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<tr class="cart-subtotal">
<th>Subtotal</th>
<td><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>713.99</bdi></span></td>
</tr>
我需要713.99
。
我该怎么做?我知道我可以从 bdi 内部获取它:
<p id="demo"></p>
<script>
var str = $('bdi').clone().find('span').remove().end().text().split('"')[1]
document.getElementById("demo").innerHTML = str;
</script>
但是如果具体地 class="cart-subtotal" 我该怎么办?
效率不高,但适合你的情况。
var re = /(\d+\.\d+)/.exec($(".woocommerce-Price-amount").html());
那么你可以通过取第一个元素 re[0]
来达到它
这个问题已经提出,但我需要一些不同的东西,我不知道它是否可能。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<tr class="cart-subtotal">
<th>Subtotal</th>
<td><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>713.99</bdi></span></td>
</tr>
我需要713.99
。
我该怎么做?我知道我可以从 bdi 内部获取它:
<p id="demo"></p>
<script>
var str = $('bdi').clone().find('span').remove().end().text().split('"')[1]
document.getElementById("demo").innerHTML = str;
</script>
但是如果具体地 class="cart-subtotal" 我该怎么办?
效率不高,但适合你的情况。
var re = /(\d+\.\d+)/.exec($(".woocommerce-Price-amount").html());
那么你可以通过取第一个元素 re[0]
来达到它