如何从<input type=date>在jQuery数据表的单元格内部

How do I get the value from <input type=date> inside a cell in jQuery DataTables?

本文关键字:数据表 jQuery 内部 单元格 input type date      更新时间:2023-09-26

我有一个动态创建(当我点击单元格)<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);
});

任何想法?

SOLUTION

使用下面的代码访问第一列(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());
});
演示