![](/img/trans.png)
[英]How do i get a value from a cell in jquery datatables clicking on dropdown inside a row
[英]How do I get the value from <input type=date> inside a cell in jQuery DataTables?
我在DataTable的單元格內有一個動態創建的(當我單擊該單元格時) <input type=date>
。
我可以選擇日期並且看起來不錯,現在我可以迭代遍歷表中的所有數據,因為我處理了每一行的數據,效果也很好,問題是當我想從這些輸入中獲取值時。
我嘗試使用data()
和node()
但是未在HTML上顯示該值,因為我發現這是應該的方式,所以我無法從HTML中獲取它,因此我嘗試了以下操作代碼,並說它是未定義的。
table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
// Tried this - return undefined
var node = this.node();
alert(node.cells[0].value);// The typeof(node.cells[0]) is object HTMLTableCellElement
// also this - here shows the HTML without the updated date
var data = this.data();
alert(data);
});
有任何想法嗎?
使用下面的代碼訪問第一列( column: 0
)中單元格內部的input
值。
var table = $('#example').DataTable();
table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
var cell = table.cell({ row: rowIdx, column: 0 }).node();
console.log($('input', cell).val());
});
有關代碼和演示,請參見此jsFiddle 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.