[英]How to get the values in an appended table row using onchange event?
I have an ajax function that gets the values from the database and then appends those data to a table. 我有一个ajax函数,该函数从数据库获取值,然后将这些数据附加到表中。 Now, there are instances that there will be 2 or more records from the database that are being retrieved, so 2 or more table rows are also appended.My problem is, how would I able to get the values of a specific row using onchange event since I have included a select option values in the table row being appended. 现在,有一些实例将从数据库中检索2条或更多条记录,因此还附加了2条或更多条表行。我的问题是,如何使用onchange事件获取特定行的值因为我在要附加的表行中包含一个选择选项值。 I know its a bit confusing but can anybody help me with this? 我知道这有点令人困惑,但是有人可以帮助我吗? Thanks a lot. 非常感谢。 Here are my codes. 这是我的代码。
$.post("{{ url('create_po') }}", { 'prod_IDs': valArray }, function(data){
var obj = JSON.parse(data);
for(var i = 0; i < obj.prodval.length; i++){
txt += "<tr class='info '><td><input type='number' class='form-control' style='width:100px;' value='0'/>"+
"</td><td>"+obj.prodval[i].unit+
"</td><td>"+obj.prodval[i].pharmaceutical+
"</td><td>"+obj.prodval[i].packaging+
"</td><td><input type='text' class='form-control' style='width:100px;' value='"+obj.prodval[i].price+"' disabled=disabled />"+
"</td><td><input type='text' class='form-control' style='width:100px;' value='0' disabled=disabled />"+
"</td></tr>";
}
$("#tbl-po-list").append(txt);
});
My table 我的桌子
<table id="tbl-po-list">
<tbody id="po-create"></tbody>
</table>
Output: 输出:
My revised table 我的修改表
How can I get the values in a row using onchange event of the quantity represented as QTY in the image above? 如何使用上图中表示为QTY的数量的onchange事件连续获取值? Please please help. 请帮忙。 Thanks a lot. 非常感谢。
Please use jQuery's Event delegation. 请使用jQuery的事件委托。
$( '#tbl-po-list' ).on( 'change' , 'input[type="number"]' ,function(){
alert( 'Event fired' );
});
Did not mock the ajax request rather just appending a new row to the table on the click of a button in the below fiddle: https://jsfiddle.net/ehcwhd7f/ 没有嘲笑ajax请求,只是在单击以下小提琴中的按钮时将新行添加到表中: https : //jsfiddle.net/ehcwhd7f/
业余答案提醒:
table.rows[0].cells[0].children[0].value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.