我实例化了一个数据表,它工作正常。但是我在JS函数中访问它时收到错误。错误是:未捕获的TypeError:$(...)。dataTable不是函数我使用的代码是:$( document ).ready(function() { //datatable instantiation $('#table-servicos').DataTable({ "order": [[ 0, "desc" ]] });});function test() { //checkin:1407 Uncaught TypeError: $(...).dataTable is not a function $('#table-servicos').dataTable().order([2, 'desc']).draw(); }
2 回答

慕婉清6462132
TA贡献1804条经验 获得超2个赞
您的代码正确,但有错字。它DataTable不是dataTable。更新代码,它应该可以按预期工作。每个开发人员都感叹这是非常疏忽的!。
$( document ).ready(function() {
//datatable instantiation
$('#table-servicos').DataTable({
"order": [[ 0, "desc" ]]
});
});
function test() {
$('#table-servicos').DataTable().order([2, 'desc']).draw();
}

慕慕森
TA贡献1856条经验 获得超17个赞
初始化表后,您必须在表上使用DataTable,并使用大写D。
$('#table-servicos').DataTable().order([2, 'desc']).draw();
添加回答
举报
0/150
提交
取消