简体   繁体   English

如何获取jquery表中文本框的值

[英]How to get the value value of textbox inside jquery table

I am working on jquery table from this table i get row data using checkbox, i have some textboxes in this table here is problem with these textboxes when i checked first row the values in the textboxes get correctly and then when i checked the 2nd row the td text changed but the textbox values of 2nd row does not change it remain same as on first one row, i want to get the proper values of each row help me with it. 我正在此表上的jQuery表上工作,我使用复选框获取行数据,我在此表中有一些文本框,当我检查第一行时文本框的值正确获得然后再检查第二行时,这些文本框存在问题td文本已更改,但第二行的文本框值未更改,仍与第一行相同,我想获取每一行的正确值以帮助我。

Jquery Table This is how i populate it jQuery Table这是我如何填充它

 $.each(list, function (key, value) {
                        var html = $(
                             '<tr>' +
                             '<td>' + value.Id + '</td>' +                            
                             '<td>' + value.FeeHeadName + '</td>' +
                             '<td>' + value.SchoolName + '</td>' +
                             '<td>' + value.ClassName + '</td>' +
                             '<td>' + value.Amount + '</td>' +
                             '<td>' + "<input type='text'  name='Paid' id='paid'/>" + '</td>' +
                             '<td>' + "<input type='text' id='Discount' name='Discount' />" + '</td>' +
                             '<td>' + "<input type='text' id='NetAmount' name='NetAmount' />" + '</td>' +
                             '<td>' + "<input type='checkbox' class='ckb'/>" + '</td>' +                            
                             '</tr>');
                        $("#view").append(html);
                        html = '';
                    });

I have attached the table image 我已附上桌子图片 在此处输入图片说明

How i get the values 我如何获得价值

$('#view').on('click', 'input[type="checkbox"]:checked', function () {
                    var row = $(this).closest('tr');
                    var id = row.find('td:eq(0)').text();
                    var fname = row.find('td:eq(1)').text();
                     var sname = row.find('td:eq(2)').text();
                     var cname = row.find('td:eq(3)').text();
                     var amount = row.find('td:eq(4)').text();
                     var paid = $('#paid').val();
                     var discount = $('#Discount').val();
                     var netAmount = $('#NetAmount').val();

                     info.push({
                         Fee_Id: id,
                         FeeHeadName: fname,
                         sname: sname,
                         cname: cname,
                         Amount: amount,
                         Paid: paid,
                         Discount: discount,
                         NetAmount: netAmount
                     });
                     console.log(info);                    
                });

Attached image of 1st row console data 第一行控制台数据的附加图像 在此处输入图片说明

Attached image of 2st row console data 第二行控制台数据的附加图像 在此处输入图片说明

you need to get the input's value from the row : 您需要从该行获取输入的值:

var paid = row.find('#paid').val();
var discount = row.find('#Discount').val();
var netAmount = row.find('#NetAmount').val();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM