错误: dataTable不是一个函数。

5

我试图使用datatables插件,但是在调用函数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()的函数吗? - domdomcodecode
2个回答

9
对我来说,将定义移出框框是有效的。
而不是。
<script type="text/javascript">
    $(function () {
        $('#tableID').dataTable();
    });
</script>

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

"并且它运行得非常完美。"

6
在我的情况下:
我正在包含

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

在页面上两次出现:在页眉和</body>之前。当我去掉其中一个时,问题就解决了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接