【问题标题】:$(...).DataTable is not a function$(...).DataTable 不是函数
【发布时间】:2016-10-07 06:18:26
【问题描述】:

我在 jquery 中使用数据表但无法正常工作。我可以搭把手。这是脚本。谢谢! #userList 是一个 div,它包含一个表条带表压缩顺序列表边框。谢谢!

 $('#userList').DataTable({
    sortable: true,
    processing: true,
    serverSide: true,
    ajax: {
        url: 'include/dades_customers.php',
        type: 'POST'
    },
    columns: [
        {"data": "CustName"},
        {"data": "Address1"},
        {"data": "Address2"},
        {"data": "City"},
        {"data": "PostCode"},
        {"data": "State"},
        {"data": "Country"},
        {"data": "Phone"},
        {"data": "Fax"},
        {"data": "Web"}
    ],
    lengthMenu: [ 2, 5, 10, 25, 50, 75, 100 ],
    //dom: '<"H"fi>rt<"F"lp><"clear">'

    dom: '<"top"fiB><"content"rt><"footer"lp><"clear">',
    buttons: [ 'colvis' ]

    /*footerCallback: function( tfoot, data, start, end, display ) {
        var api = this.api();
        $( api.column( 5 ).footer() ).html(
            api.column( 5 ).data().reduce( function ( a, b ) {
                return a + b;
            }, 0 )
        );
    }
    */  
});

【问题讨论】:

  • 您是否包含所有文件?还有jquery?
  • 是的!这是包括的
  • 如果没有定义,你可能没有添加合适的插件。
  • 什么没有定义?

标签: jquery


【解决方案1】:

要使用DataTable,请在页面顶部添加以下引用。请注意顺序问题:

<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>

【讨论】:

    【解决方案2】:

    我认为问题出在你所说的:

    #userListdiv

    我认为#userList 不能是div 标签。它必须是 table 标签的 id。

    【讨论】:

      猜你喜欢
      • 2016-04-09
      • 2015-08-19
      • 2015-09-22
      • 2018-12-16
      • 2017-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多