0
我在使用javascript從按鈕單擊時從父類拉入值時遇到了麻煩。我將在按鈕選擇上激發JavaScript,並且需要它爬上Dom樹並從「product-sku」類中提取值。在深入瞭解這篇文章後https://gomakethings.com/climbing-up-and-down-the-dom-tree-with-vanilla-javascript/我知道我必須在按鈕選擇前面加上我的腳本,但我不確定是否可以通過這種方式在樹上移動,思考?從GTM的Javascript中的父類中拉取值
<div class="review-sku-line">
<div class="ratings">
<span class="amount"><a href="#" onclick="var t = opener ? opener.window : window; t.location.href='xxxx/review/product/list/id/123456/category/117/'; return false;">No Reviews</a></span>
</div>
<div class="product-sku">
<span><strong>Code:</strong> 7777</span>
</div>
</div>
<div class="actions">
<form class="add-form cart-update-flag" method="post" action="xxxxx/checkout/cart/add/uenc/aHR3dUuaHRtbA,,/product/123456/form_key/cV1MQZ1w/">
<input type="hidden" name="block_name" value="xxxxxx/_list_item_render_gridview">
<div class="qty-control small">
<button type="button" for="qty_prod_123456" class="qty-ctrl-sub button">
<span class="grey-btn"><i class="icon-minus"></i></span>
</button>
<input id="qty_prod_123456" type="text" class="qty" name="qty" value="1">
<button type="button" for="qty_prod_123456" class="qty-ctrl-add button">
<span class="orange-btn"><i class="icon-plus"></i></span>
</button>
</div>
<button class="button btn btn-cart" title="Add to Cart" type="submit">
<span>Add to Cart</span>
</button>
</form>
</div>
</div>
非常感謝您的任何建議或意見!