gpt4 book ai didi

javascript - 如何使用 DOM 隔离元素

转载 作者:行者123 更新时间:2023-11-30 14:04:44 24 4
gpt4 key购买 nike

我正在尝试隔离此页面上的订单总数: 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com