Javascript 函数将行添加到jquery中的dataTable中,该函数给出了TypeError

Javascript 函数将行添加到jquery中的dataTable中,该函数给出了TypeError,javascript,jquery,html,Javascript,Jquery,Html,在我的Jquery数据表中,row.add不起作用,并抛出一个错误,表示add函数未定义。错误消息是: Uncaught TypeError: Cannot read property 'add' of undefined html <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr>

在我的Jquery数据表中,
row.add
不起作用,并抛出一个错误,表示add函数未定义。错误消息是:

Uncaught TypeError: Cannot read property 'add' of undefined

html

<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Column 1</th>
                <th>Column 2</th>
                <th>Column 3</th>
            </tr>
        </thead>

        <tfoot>
            <tr>
                <th>Column 1</th>
                <th>Column 2</th>
                <th>Column 3</th>
            </tr>
        </tfoot>
    </table>
<button id="addRow">Add new row</button>
在此代码中,
prntTable
未定义。请将其定义为全局变量或在单击函数中重新定义

添加

var prntTable = $('#example').DataTable();   
单击功能之后


而不是:

var prntTable = $("#example").dataTable();
var prntTable = $("#example").DataTable();
试试看:

var prntTable = $("#example").dataTable();
var prntTable = $("#example").DataTable();

看起来旧的datatables API
dataTable()
不支持您正在调用的函数。将新API与:
DataTable()
一起使用。阅读此处了解更多信息:

尝试使用FNADDATA它对我有用

table.fnAddData(['1','1','2','3','4']);

我收到错误Uncaught TypeError:无法读取undefined的属性“add”小提琴对我来说很好..你检查过吗..未定义的错误是由于上述原因造成的。请在签入它之前清除浏览器缓存:)我认为需要注意的是,安克尔下面的回答有助于澄清答案。尽管Outlooker说要使用DataTable,但我在第一次阅读它时就忽略了大写字母D。如果使用dataTable,则table.row.add()将不起作用。您必须使用DataTable。这解决了我的问题,我在Outlooker的小提琴中验证了它。这解决了我的问题。旧的dataTable()甚至不应该存在;我得到错误表。fnAddData不是函数