[英]JQuery get selected option value for different row
I have a problem with selected option value for different row.我对不同行的选定选项值有问题。 I succeed to get value for first row.
我成功获得了第一行的价值。 What i want to do is different row item have different price.
我想要做的是不同的行项目有不同的价格。
My previous question about "JQuery Get Selected Option Value for Add Row" has been solved : Here我之前关于“JQuery Get Selected Option Value for Add Row”的问题已经解决: 这里
Now, i come out with another issues which is to get different value for different row.现在,我提出了另一个问题,即为不同的行获得不同的值。 The picture sample is like below
图片示例如下
My problem sample screenshot我的问题示例截图
Here's the code for my JS :这是我的 JS 代码:
var i=$('table tr').length; $(".tambah_sofa").on('click',function(){ /* add new row function start here */ html = '<tr id="row_'+i+'">'; html += '<td><button type="button" id="delete-button" data-row-delete="row_'+i+'">X</button></td>'; html += '<td><select id="sofa_'+i+'"><option value="10">hai</option><option value="20">20</option> <option value="50">50</option></select></td>'; html += '<td>X</td>'; html += '<td><input type="number" name="quantity[]" id="quantity_'+i+'" value="1" disabled="disabled"></td>'; html += '</tr>'; sidebar = '<tr id="row_'+i+'">'; sidebar += '<td><input style="width:50%;" name="sofa'+i+'" type="text" id="price_sofa'+i+'" value="" disabled="disabled"></td>'; sidebar += '</tr>'; $('#table_item').append(html); $('#table_sidebar').append(sidebar); /* Get selected option value start here */ $('body').on('change', '#sofa_'+i+'', function () { $('#price_sofa'+i+'').val($(this).find('option:selected').val()); }); /* Get selected option value end here */ i++; });
var i = $('table tr').length;
$(".tambah_sofa").on('click', function() {
/* add new row function start here */
html = '<tr id="row_' + i + '">';
html += '<td><button type="button" id="delete-button" data-row-delete="row_' + i + '">X</button></td>';
html += '<td><select id="sofa_' + i + '"><option value="10">hai</option><option value="20">20</option> <option value="50">50</option></select></td>';
html += '<td>X</td>';
html += '<td><input type="number" name="quantity[]" id="quantity_' + i + '" value="1" disabled="disabled"></td>';
html += '</tr>';
sidebar = '<tr id="row_' + i + '">';
sidebar += '<td><input style="width:50%;" name="sofa' + i + '" type="text" id="price_sofa' + i + '" value="" disabled="disabled"></td>';
sidebar += '</tr>';
$('#table_item').append(html);
$('#table_sidebar').append(sidebar);
/* Get selected option value start here */
(function(index){
$('#sofa_' + index).on('change', function () {
$('#price_sofa' + index).val($(this).val());
});
})(i);
/* Get selected option value end here */
i++;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.