[英]How to store the values of an appended table row in an array variable using onchange event?
[英]How to get the values in an appended table row using onchange event?
我有一個ajax函數,該函數從數據庫獲取值,然后將這些數據附加到表中。 現在,有一些實例將從數據庫中檢索2條或更多條記錄,因此還附加了2條或更多條表行。我的問題是,如何使用onchange事件獲取特定行的值因為我在要附加的表行中包含一個選擇選項值。 我知道這有點令人困惑,但是有人可以幫助我嗎? 非常感謝。 這是我的代碼。
$.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);
});
我的桌子
<table id="tbl-po-list">
<tbody id="po-create"></tbody>
</table>
輸出:
我的修改表
如何使用上圖中表示為QTY的數量的onchange事件連續獲取值? 請幫忙。 非常感謝。
請使用jQuery的事件委托。
$( '#tbl-po-list' ).on( 'change' , 'input[type="number"]' ,function(){
alert( 'Event fired' );
});
沒有嘲笑ajax請求,只是在單擊以下小提琴中的按鈕時將新行添加到表中: https : //jsfiddle.net/ehcwhd7f/
業余答案提醒:
table.rows[0].cells[0].children[0].value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.