由于需要第三方插件,我正在尝试使用标准 JavaScript 重写以下 jQuery 方法,但到目前为止我还没有找到方法。
var productprice = $(".product-listing:nth-child(2)").html();
我已经尝试过了,但没有成功
var productprice = document.getElementsByClassName("product-listing")[1].innterText;
最佳答案
我认为您使用的解决方案是错误的。 “innerText”有错字,应该是这样的。
var productprice = document.getElementsByClassName("product-listing")[1].innerText;
替代:也可以使用innerHtml代替innerText。
var productprice = document.getElementsByClassName("product-listing")[1].innerHtml;
关于javascript - 尝试使用标准 JavaScript 来定位类和第 n 个子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28208540/