cart.js 这不起作用 控制台中未打印任何内容或某些声明有误 迅速回答
var updateBtns = document.getElementsByClassName('update-cart')
for(var i=0 ; i<updateBtns.length ; i++)
{
updateBtns[i].addEventListener('click',function(){
var productId = this.dataset.product
var action = this.dataset.action
console.log(productId,action)
})
}
html代码中有错误吗
{% for product in products %}
{% if product.category == "Dosa" %}
<div class="product">
<tr>
<td><h5>{{ product.name }}</h5></td>
<td><h5>{{ product.price }}</h5></td>
<td><button data-product={{product.id}} data-action="add" class="btn btn-warning btn-add update-cart">Add to cart</button></td>
</tr>
</div>
{% endif %}
{% endfor %}
似乎工作得很好。我建议在匿名/私人模式下检查一次。可能是缓存的问题
相关问题 更多 >
编程相关推荐