簡體   English   中英

數據表不起作用

[英]Datatable is not working

我正在使用數據表搜索表content。但是數據表不能在我的html代碼中工作
我想為我的表引入過濾和排序功能。html腳本中包含的所有表庫

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">

    <!-- jQuery -->
    <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>

    <!-- DataTables -->
    <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
    </head>

    <body>
    <script type="text/javascript">
    $('table').dataTable();
    </script>
    <table style="margin-top:100px">
    <thead>
    <tr class='header'>
    <th>Name</th>
    <th>Party</th>
    <th>Constituency</th>
    <th>Gender</th>
    </tr>
    </thead>
    <tbody><tr>
    <th>pom</th>
    <th>1</th>
    <th>bachni</th>
    <th>male</th>
    </tr>
    <tr>
    <th>santosh</th>
    <th>2</th>
    <th>bachni</th>
    <th>male</th>
    </tr>
    <tr>
    <th>deepak</th>
    <th>3</th>
    <th>bachni</th>
    <th>male</th>
    </tr>
    <tr>
    <th>sudhir</th>
    <th>1</th>
    <th>savarde</th>
    <th>male</th>
    </tr>
    </tbody>
    </table>
    </body>
    </html>

由於您已將腳本放置在DOM之前,因此需要將jQuery代碼放入DOM准備就緒處理程序$(document).ready(function() {...}); 或更短的$(function(){...}):

此步驟用於確保在執行jQuery代碼之前已將所有DOM元素均加載到頁面中:

$(function() {
   $('table').dataTable();
});

現在嘗試下面的代碼可以正常工作:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">

    <!-- jQuery -->
    <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>

    <!-- DataTables -->
    <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
    </head>

    <body>
    <script type="text/javascript">
    $('table').dataTable();
    </script>
    <table style="margin-top:100px" class="table table-striped table-bordered datatable dataTable">
    <thead>
    <tr class='header'>
    <th>Name</th>
    <th>Party</th>
    <th>Constituency</th>
    <th>Gender</th>
    </tr>
    </thead>
    <tbody><tr>
    <th>pom</th>
    <th>1</th>
    <th>bachni</th>
    <th>male</th>
    </tr>
    <tr>
    <th>santosh</th>
    <th>2</th>
    <th>bachni</th>
    <th>male</th>
    </tr>
    <tr>
    <th>deepak</th>
    <th>3</th>
    <th>bachni</th>
    <th>male</th>
    </tr>
    <tr>
    <th>sudhir</th>
    <th>1</th>
    <th>savarde</th>
    <th>male</th>
    </tr>
    </tbody>
    </table>
<script>
$(function() {
      $('table').dataTable();
});
</script>
    </body>
    </html>

請檢查這個小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM