【发布时间】:2015-12-02 16:33:18
【问题描述】:
我有一个将值传递给 django 视图的表单。
在表单中有一个带有复选框的动态生成的表格。
HTML:
<table class="table table-striped">
<thead>
<tr>
<th><input type="checkbox" onClick="toggle(this, 'no')"></th>
<th>Order Id</th>
<th>Channel</th>
<th>Dispatch By Date</th>
<th>Amount</th>
<th>Status</th>
<th>Products</th>
</tr>
</thead>
<tbody>
{% for oid,oiid,dbd,stts,tp,sku,qty,chnl in new_orders %}
<tr>
<td><input type="checkbox" name="no" value="{{oid}}"></td>
<td>
<div><a class="btn-link" href="#">{{oid}}</a></div>
<div><input name="oiid" style="display:none" value="{{oiid}}">{{oiid}}</div>
</td>
<td>{{chnl}}<input name="channel" style="display:none" value="{{chnl}}"></td>
<td><span class="text-muted"><i class="fa fa-clock-o"></i> {{dbd}}</span></td>
<td>{{tp}}</td>
<td>{{stts}}</td>
<td>
<div>{{sku}}</div>
<div>Quantity: {{qty}}</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
我将 3 个值传递回我的视图。 oid, oiid, chnl。
问题是如果我选择一些元素而不是全部,那么所有 oid 的值都会为这些元素传递,但 oiid 和 chnl 的所有值都会传递。
我的 Javascript:
function toggle(source, text) {
checkboxes = document.getElementsByName(text);
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
如何只传递为所有三个变量选择的值?
【问题讨论】:
-
那么……我的回答对你有帮助吗?
标签: javascript html django