0
我有一個像下面這樣的jQuery腳本,我想在name='service_id["+kode+"]'
上設置kode
的遞增數字。問題是數字還沒有遞增,只是顯示1.迭代數在'.each'jquery
如何設置增量行數?
這裏是我的腳本:
function getCorporateService(id){
// get data and parsing to column
$.get("{{ url('salesorder/service')}}/"+id, function(data){
console.log(id);
console.log(data);
var kode = 0;
$.each(data, function (index, element){
kode++;
$br = "<tr id='item'>";
$br += "<td> <input class='input-small' type='text' id='order_identifier' name='order_identifier' readonly></td>";
$br += "<td><input class='input-small' type='text' id='service_id["+id+"]' name='service_id["+kode+"]' value='"+element.service_name+"' readonly></td>";
$br += "<td><select id='order_type["+id+"]' name='order_type["+id+"]'> <option> - </option> <option value='add'>Add</option> <option value='change'>Change</option> <option value='cancel'>Cancel</option> </select></td>";
$br += "<td><input class='input-small' type='text' id='select_plan["+id+"]' name='select_plan["+kode+"]'></td>";
$br += "<td><input class='input-mini' type='text' id='qty["+id+"]' name='qty["+kode+"]' value='1' onChange='getTotalPrice("+id+")'></td>";
$br += "<td><input class='input-small' type='text' id='unit_price["+id+"]' name='unit_price["+kode+"]' onChange='getTotalPrice("+id+")'></td>";
$br += "<td><input class='input-small' type='text' id='total_price["+id+"]' name='total_price["+kode+"]' onChange='getTotalPrice("+id+")'></td>";
$br += "<td><textarea class='input-small' id='notes["+id+"]' name='notes["+kode+"]'></textarea></td>";
$br += "</tr>";
$(".corporatesvc").append($br);
});
});
}
所以,只要使用'index'? – Cerbrus
如果你想讓kode增加,你必須把這個值賦值回kode,就像這個kode = kode + 1一樣,而且你不需要使用一個增量變量,你可以直接使用索引 – GraveyardQueen
@GraveyardQueen:他已經增加了kode ':'kode ++;' – Cerbrus