【问题标题】:django cart.js loop is not runningdjango cart.js 循环没有运行
【发布时间】:2021-05-23 08:41:14
【问题描述】:

购物车.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 %}

【问题讨论】:

  • 确保您的 JavaScript 仅在加载正文后运行。

标签: javascript python django e-commerce cart


【解决方案1】:

似乎运行良好。我建议请在隐身/私人模式下检查一次。可能是缓存的问题...

【讨论】:

    猜你喜欢
    • 2023-03-06
    • 1970-01-01
    • 2022-01-18
    • 2019-02-24
    • 2015-05-08
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 2021-05-17
    相关资源
    最近更新 更多