我正在尝试隔离此页面上的订单总数: https://www.brawtaliving.com/checkout/order-received/3014/?key=wc_order_zzPLbJK6Tnsjy
我已经能够使用以下方法缩小到包含订单总数数字的 HTMLCollection:
console.log(document.getElementsByClassName('woocommerce-Price-amount amount'))
但我怎样才能缩小到只显示 $78,334.00?
这是我得到的 HTMLCollection - 价格在第一个中:
<span class="woocommerce-Price-amount amount" onclick="window.location='undefined'" style="cursor: pointer;">…</span>
<span class="woocommerce-Price-amount amount" onclick="window.location='undefined'" style="cursor: pointer;">…</span>
<span class="woocommerce-Price-amount amount" onclick="window.location='undefined'" style="cursor: pointer;">…</span>
<span class="woocommerce-Price-amount amount" onclick="window.location='undefined'" style="cursor: pointer;">…</span>
最佳答案
引用 JQuery text()
了解更多细节,这个解决方案对我有用
console.log($('li.total .woocommerce-Price-amount.amount').text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<li class="total">
Total:
<strong>
<span class="woocommerce-Price-amount amount" onclick="window.location='undefined'" style="cursor: pointer;">
<span class="woocommerce-Price-currencySymbol">$</span>78,334.00
</span>
</strong>
</li>
</body>
关于javascript - 如何使用 DOM 隔离元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55661299/