<div class="quantity-selector">
<span class="quantity-element decrease_qty">-</span>
<span class="quantity-element quantity-digit">1</span>
<input type="hidden" value="1" name="quantity">
<span class="quantity-element increase_qty">+</span>
</div>
尝试从&#34;数量元素数量数字&#34;获取innerhtml班级
答案 0 :(得分:4)
如果你想要一个非jQuery方法,这将适用于IE8及以上版本(当然还有其他任何现代浏览器):
var html = document.querySelector(".quantity-element.quantity-digit").innerHTML;
答案 1 :(得分:1)
当你标记jQuery时,试试这个:
var innerHtml = $('.quantity-element.quantity-digit').html(); // = 1
答案 2 :(得分:0)
HTML:
<div class="quantity-selector">
<span class="quantity-element decrease_qty">-</span>
<span class="quantity-element quantity-digit">Hi user3142655</span>
<input type="hidden" value="1" name="quantity">
<span class="quantity-element increase_qty">+</span>
</div>
JavaScript的:
console.log (document.getElementsByClassName("quantity-element quantity-digit")[0].innerHTML);