简体   繁体   English

如何使用onchange事件获取附加表行中的值?

[英]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.

相关问题 如何使用onchange事件将附加表行的值存储在数组变量中? - How to store the values of an appended table row in an array variable using onchange event? 动态表行上的onchange事件如何添加文本参数 - onchange event on dynamic table row how to add text param 在反应中,如何使用onChange事件定位特定的表行? - In react, how to target specific table row with onChange event? 如何使用jQuery数据表的onChange事件从html select标签选项值中获取值? - How to get value from html select tag option value using onChange event using jQuery data table? 如何使用jQuery数据表的onChange事件获取所选数据? - How to get selected data using onChange event using jQuery Data table? 提交表单后,如何使用JQuery从附加到HTML表的字段中获取$ _POST数组中的值? - How to get the values in $_POST array from the fields which are appended to the HTML table using JQuery after form submission? 对表中的每一行运行OnChange事件-MVC - Run OnChange event for each row in table - MVC 如何在不使用更改或 onclick 事件的情况下获取动态附加选项? - How to get dynamically appended options without using on change or onclick event? 如何使用 onChange 事件对多个输入的值进行求和、除法 | 反应JS - How to sum, divide values of multiple inputs using onChange event | ReactJS 如何使用 onChange 事件对多个输入的值求和 | ReactJS - How to sum values of multiple inputs using onChange event | ReactJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM