<table id="table" class="table table-bordered table-hover dataTable" style="width:100%"> <thead> <tr> <th>RM Code</th> <th style="width:10%">Wh</th> <th style="width:10%">Quantity <br>Recipe</th> </tr> </thead> <tbody> <tr class="details"> <td> <input type="text" name="code[]" placeholder="Enter your Name" class="form-control name_list" /> </td> <td> <input type="text" name="wh[]" placeholder="Enter your Name" class="form-control name_list" /> </td> <td> <input type="text" name="qty[]" placeholder="Enter your Name" class="form-control name_list" /> </td> </tr> </tbody></table>如何從上面的數據表中獲取數量值。我試過了$('#table tbody').on('change', 'td', function(e) { alert(dtable.cell(this).data());});我仍然無法從我的輸入字段中獲得價值..
2 回答

慕妹3146593
TA貢獻1820條經驗 獲得超9個贊
為您提供兩種解決方案。第一個實際上與您的方法相符。但是,這是不合適的,因為當表格行中的任何輸入字段發生更改時,用戶會收到警報,因此,不僅僅是數量字段
$('#table tbody').on('change', 'td', function(e) {
var data = $('td').find('input[name="qty[]"]').val();
alert(data);
});
第二個,更方便。僅當數量字段更改時,用戶才會收到警報。有了這個,您需要將一個類添加到數量表數據中
<td class="price">
<input type="text" name="qty[]" placeholder="Enter your Name" class="form-control name_list" />
</td>
把它當作
$('#table tbody').on('change', 'td.price', function(e) {
var data = $(this).find('input').val();
alert(data);
希望能幫助到你

慕虎7371278
TA貢獻1802條經驗 獲得超4個贊
var data = dtable.row(this).nodes().to$().find('input[name="rm_code[]"]').val();
- 2 回答
- 0 關注
- 137 瀏覽
添加回答
舉報
0/150
提交
取消