亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

數據表不顯示數據

數據表不顯示數據

夢里花落0921 2023-05-25 17:19:58
我已經像網站提供的那樣包含了 CDN,即使復制粘貼了每一行代碼,仍然無法顯示或顯示任何結果。這是CDN<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.css"><script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.js"></script>這是我的代碼<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.css"><script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.js"></script><body><table id="example" class="display">    <thead>        <tr>            <th>Name</th>            <th>Position</th>            <th>Salary</th>        </tr>    </thead></table></body>這是腳本[    {        "name":       "Tiger Nixon",        "position":   "System Architect",        "salary":     "$3,120"    },    {        "name":       "Garrett Winters",        "position":   "Director",        "salary":     "$5,300"    }]$('#example').DataTable( {    data: data,    columns: [        { data: 'name' },        { data: 'position' },        { data: 'salary' }    ]} );
查看完整描述

2 回答

?
富國滬深

TA貢獻1790條經驗 獲得超9個贊

你錯過了兩件事:

  1. JQuery 庫

  2. 變量data_

請檢查以下解決方案。

var data = [{

    "name": "Tiger Nixon",

    "position": "System Architect",

    "salary": "$3,120"

  },

  {

    "name": "Garrett Winters",

    "position": "Director",

    "salary": "$5,300"

  }

]

$('#example').DataTable({

  data: data,

  columns: [{

      data: 'name'

    },

    {

      data: 'position'

    },

    {

      data: 'salary'

    }

  ]

});

<html>

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.css">

<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>

<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.js"></script>


<body>

<table id="example" class="display">

    <thead>

        <tr>

            <th>Name</th>

            <th>Position</th>

            <th>Salary</th>

        </tr>

    </thead>

</table>

</body>

</html>


查看完整回答
反對 回復 2023-05-25
?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

jquery datatables.js 需要jquery。你應該在 jquery.datatables.js 之前添加它。


 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.css">

     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

     <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.js"></script>



  And you even don't need to define columns in your datatable, datatables does the work itself :




    <body>

       <table id="example" class="display" width="100%"></table>

    </body>




    <script>


    var dataSet = [

      [ "Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800" ],

      [ "Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750" ],

   

    ];


    $(document).ready(function() {

      $('#example').DataTable( {

         data: dataSet,

         columns: [

            { title: "Name" },

            { title: "Position" },

            { title: "Office" },

            { title: "Extn." },

            { title: "Start date" },

            { title: "Salary" }

         ]

      } );

     } );

    </script>


查看完整回答
反對 回復 2023-05-25
  • 2 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號