【发布时间】:2021-12-24 22:36:17
【问题描述】:
我想制作一个商品部分,您可以在其中“+”和“-”增加或减少商品数量 然后,根据数量,“出售”它。
现在我们需要将值 {{ el.id }} 传递给 django 视图
我的代码: html:
<form method="POST">
{% csrf_token %}
{% for el in form3 %}
{% if el.count > 0 %}
[ {{ el.count }}шт. ] <br>
[ {{ el.title }} ]<br>
<a id="minus{{ el.id }}" href="#"><b>[ - ]</b></a>
<span id="value{{ el.id }}">0</span>
<a id="plus{{ el.id }}" href="#"><b>[ + ]</b></a>
<br>
Function where i + or - from count
<script>
$(function(){
var valueElement = $('#value{{ el.id }}');
function incrementValue(e){
valueElement.text(Math.max(parseInt(valueElement.text()) + e.data.increment, 0));
return false;
}
$('#plus{{ el.id }}').bind('click', {increment: 1}, incrementValue);
$('#minus{{ el.id }}').bind('click', {increment: -1}, incrementValue);
});
</script>
{% endif %}
{% endfor %}
</form>
我如何使用“span id=value{{ el.id }}”获取值
【问题讨论】:
-
为什么,你可以向服务器发送一个 HTTP 请求并减少或增加该值。您可以填写
href。
标签: javascript python html jquery django