简体   繁体   English

新手 JS DataTables 问题:如何启动它?

[英]Newbie JS DataTables question: How to initiate it?

Sorry for asking very newbie question, but I am completely new to web development and trying to build a simple 1-page site which will reflect some "table" data using DataTables package. I tried enomorous amount of different ways to initiate it, but with not much success.很抱歉问了一个新手问题,但我对 web 开发完全陌生,并尝试构建一个简单的单页站点,该站点将使用 DataTables package 反映一些“表格”数据。我尝试了大量不同的方法来启动它,但是没有太大的成功。

What I am doing wrong?我做错了什么? My code:我的代码:

<html>
<head>
    <link rel="stylesheet" type="text/css" href="/DataTables/datatables.css">

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" charset="utf8" src="/DataTables/datatables.js"></script>

    <script type="text/javascript">


        $(document).ready(function () {
            $('#example').DataTable();
        });


    </script>
</head>
<body>
<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
    <tr>
        <th>Name</th>
        <th>Position</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>Tiger Nixon</td>
        <td>System Architect</td>
    </tr>
    <tr>
        <td>Garrett Winters</td>
        <td>Accountant</td>
    </tr>
    </tbody>
</table>
</body>
</html>

Assuming you mean this plugin: https://datatables.net/假设你的意思是这个插件: https://datatables.net/

You are using an old version of jQuery that is not compatible with this plugin.您使用的是与此插件不兼容的旧版本 jQuery。 1.11.3 is really old and it's highly recommended to update. 1.11.3 真的很旧,强烈建议更新。 Using the latest (SO) version of jQuery will fix your problem as you can see in the snippet below.使用最新 (SO) 版本的 jQuery 将解决您的问题,如下面的代码片段所示。 Any 3.x version should do the job.任何 3.x 版本都可以完成这项工作。

 $(document).ready(function () { $('#example').DataTable(); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css"> <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Name</th> <th>Position</th> </tr> </thead> <tbody> <tr> <td>Tiger Nixon</td> <td>System Architect</td> </tr> <tr> <td>Garrett Winters</td> <td>Accountant</td> </tr> </tbody> </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM