javascript - 数据表.row()未定义

标签 javascript jquery undefined datatables

我想通过简单地单击相关按钮来删除行。数据表是有效的,我可以在数据表中使用一些基本功能,例如排序和搜索,但是当我单击按钮时,它只是简单地说未定义的错误:

供您引用,我使用 datatable 1.10 和 jquery 1.10.2 enter image description here

代码:

<table cellpadding="0" cellspacing="0" border="0" class="row-border" id="table">
<thead>
    <th>Video ID</th>
    <th>Filename</th>
    <th>Action</th>
</thead>
<tbody>
    <td>1</td>
    <td>ABCD</td>
    <td><input type='button' name='deleteBtn' value='Delete' />
</tbody>
<tfoot>
    <tr>
        <th>Video ID</th>
        <th>Filename</th>
        <th>Action</th>
    </tr>
</tfoot>
</table>

<script src="jquery.min.js"></script>
<script src="jquery.dataTables.min.js"></script>
<script type="text/javascript">
var table = $('#table').dataTable( {} );

$('#table tbody').on('click',"input[type='button']",function() {
    table
        .row( $(this).parents('tr') )**
        .remove()
        .draw();
});
</script>
</body>
</html>

最佳答案

这不起作用,因为 dataTable() 之间存在巨大差异构造函数和 DataTable() 1.10.x 中引入的构造函数 ( see docs ) :

The difference between the two is that the first will return a jQuery object, while the second returns a DataTables API instance.

简单地改变

var table = $('#table').dataTable( {} );

var table = $('#table').DataTable( {} );

如果您想通过 table 使用新的 dataTables API变量。
查看您的代码正在运行 -> http://jsfiddle.net/Sd6UQ/

注意:记住使用<tr> ..</tr>并关闭 <td>是正确的。数据表对格式错误的标记非常敏感。

关于javascript - 数据表.row()未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24545916/

相关文章:

JavaScript Cookie 绝对拒绝删除

javascript - 简单的 jQuery 脚本无法执行任何操作

javascript - 用自定义异常替换 'undefined'

javascript - 如何在 JavaScript 中声明 ClassName.FunctionName.myFunction() ?

perl - 为什么我可以打开undef?

javascript - 使一个框出现在页面前面

Javascript、SetInterval 和 SetTimeOut 函数导致滚动不稳定

javascript - FabricJS Canvas drawImage 不显示图像

javascript - 在 DIV 上拖放文本

javascript - 百分比编码 JavaScript