html - 如何使用 html post 提交动态表格
问题描述
我有一个 html 表,它基本上来自我的 django 模型
<form action="{% url 'checkout' %}" method="POST">
<table id="table" class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Item</th>
<th scope="col">Quntity</th>
<th scope="col">Price</th>
</tr>
</thead>
<tbody>
{% csrf_token %}
{% for item in cartitems %}
<tr>
<th scope="row">{{ forloop.counter }}</th>
<td>{{ item.name }}</td>
<td data-count="1" id="counter_{{ forloop.counter }}">
<button onclick="minus({{ forloop.counter }})" id="minusButton" data-count="1"
class="btn btn-default btn-xs">
<i class="fas fa-minus mr-2"></i>
</button>
1
<button onclick="plus({{ forloop.counter }})" id="plusButton" data-count="1" class="btn btn-default btn-xs">
<i class="fas fa-plus ml-2"></i>
</button>
</td>
<td data-price="{{ item.price }}" id="counter_{{ forloop.counter }}">
{{ item.price }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<td>Total Price</td>
<td></td>
<td></td>
<td id='totalPrice'></td>
</tr>
</tfoot>
</table>
</div>
<div>
<button type="submit" class="btn btn-default btn-lg">Proceed To Checkout</button>
</div>
</form>
我表中的数量字段来自用户,所以我想将表中的所有数据发布到 django,请让我知道是否有任何简单的方法可以做到这一点。现在我的表格没有做任何事情。
我知道您可以通过 ajax 发布 quatity 字段,但我不希望这样,因为用户可能还会从购物车中删除一些商品
解决方案
推荐阅读
- javascript - 在@flow strict 下,对于实用功能,Object 有哪些替代方案?
- vue.js - 如何在 Nuxt.js 中设置 beforeResolve 导航守卫
- html - 多列手风琴背景滑动
- r - 如何按长/纬度值过滤 sfc 多边形?
- bookdown - 在 bookdown 书中包含 css?
- r - 绘制网络时固定节点
- r - 对于每个数据框行,找到位于某个范围内的点
- google-drive-api - 如何使用手表订阅 Google Drive 上的更改
- javascript - Google platform.js 有时不会触发 onload 回调
- python - 更新python函数中的引用变量