【问题标题】:Error dataTable is not a function错误数据表不是函数
【发布时间】:2014-04-21 12:06:35
【问题描述】:

我正在尝试使用数据表插件,但在调用函数 dataTable() 时出现错误。 我的代码如下所示:

@Scripts.Render("~/Scripts/DataTables-1.9.4/media/js/jquery.js")
@Scripts.Render("~/Scripts/DataTables-1.9.4/media/js/jquery.dataTables.js")

<script type="text/javascript">
    $(function () {
        $('#tableID').dataTable();
    });
</script>

<table class="table table-striped table-hover table-bordered" id="tableID">
    <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Row 1</td>
            <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
        </tr>
    </tbody>
</table>

当我运行它时,我可以在 Firebug 中看到一个错误:

TypeError: $(...).dataTable is not a function
$('#tableID').dataTable();

在 Firebug 中我可以看到包含 jquery.dataTables.js 文件,但函数 dataTable() 不起作用。

【问题讨论】:

  • 你的js文件里有没有叫dataTable()的函数?

标签: javascript jquery datatable


【解决方案1】:

对我来说,作品将定义移出框框

代替

<script type="text/javascript">
    $(function () {
        $('#tableID').dataTable();
    });
</script>

我用

<script type="text/javascript">
    $('#tableID').dataTable();
</script>

而且效果很好。

【讨论】:

    【解决方案2】:

    就我而言:
    我包括

    @Scripts.Render("~/bundles/jquery")
    

    在页面中出现两次:在标题处和&lt;/body&gt;之前
    当我删除它们时,问题就消失了

    【讨论】:

      猜你喜欢
      • 2014-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      • 2017-10-23
      • 2013-01-04
      • 1970-01-01
      • 2020-10-21
      相关资源
      最近更新 更多