【发布时间】:2022-01-19 16:34:54
【问题描述】:
我是 Django 的初学者,我创建结帐页面,当用户更改输入范围号时 enter image description here 它发送到服务器,但它适用于第一个 我想是因为我为所有输入设置了相同的 id 并且我无法更改它,因为它在标签中
我该如何解决?
Django 部分
class Ajax_Handler(View):
def get(self,request):
if request.is_ajax():
count=request.GET['count']
return JsonResponse({'count':count},status=200)
ajax部分
$(document).ready(function(){
var crf=$('input[name=csrfmiddlewaretoken]').val();
$("#icount").change(function(){
$.ajax({
url:'/adding',
type:'get',
data:{
count:$('#icount').val(),
},
success:function(respond){
$('#icount').val(respond.count)
}
});
});
});
html部分
<tbody>
{% for order in order.orderdetail_set.all %}
<tr>
<td class="product-image">
{% thumbnail order.product.image "100x100" crop="center" as im %}
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}
</td>
<td class="product-name"><a href="products/{{order.product.id}}">{{order.product.title}}</a></td>
<td class="product-price">{{order.product.price|intcomma:False}}تومان</td>
<td class="product-quantity">
<label>تعداد</label>
<input type="hidden" name="order_id{{order.id}}" value="{{order.id}}">
<input name='count' id='icount' min="1" max="100" value="{{order.count}}" type="number">
</td>
<td class="product-total">{{order.totalprice|intcomma:False}}</td>
<td class="product-remove"><a href="delete/{{order.id}}"><i class="fa fa-trash-o"></i></a></td>
</tr>
{% endfor %}
</tbody>
【问题讨论】: