简体   繁体   English

jQuery DataTable不是函数

[英]jQuery DataTable Not a Function

I've done a lot of searching and everyone says it is caused by including the DataTable script before jQuery, or double-including jQuery. 我做了很多搜索,每个人都说这是由于在jQuery之前包含DataTable脚本或双重包含jQuery引起的。

However, this is not the case for my code. 但是,我的代码不是这种情况。

I keep getting $(...).DataTable is not a function. 我不断得到$(...).DataTable不是一个函数。

<!DOCTYPE html>   
<html lang="en">   
<head>   
  <meta charset="utf-8">   
  <title>Example of Employee Table with twitter bootstrap</title>   
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>


    <script type="text/javascript">
        $(document).ready(function(){
            $('#myTable').DataTable();
        });
    </script>
</head>  
<body style="margin:20px auto">  
    <table id="myTable" class="table table-striped" >  
        <thead>  
          <tr>  
            <th>ENO</th>  
            <th>EMPName</th>  
            <th>Country</th>  
            <th>Salary</th>  
          </tr>  
        </thead>  
        <tbody>  
          <tr>  
            <td>001</td>  
            <td>Anusha</td>  
            <td>India</td>  
            <td>10000</td>  
          </tr>  
          <tr>  
        <td>002</td>  
        <td>Charles</td>  
        <td>United Kingdom</td>  
        <td>28000</td>  
      </tr>  
      <tr>  
        <td>003</td>  
        <td>Sravani</td>  
        <td>Australia</td>  
        <td>7000</td>  
      </tr>  
       <tr>  
        <td>004</td>  
        <td>Amar</td>  
        <td>India</td>  
        <td>18000</td>  
      </tr>  
      <tr>  
        <td>005</td>  
        <td>Lakshmi</td>  
        <td>India</td>  
        <td>12000</td>  
      </tr>  
      <tr>  
        <td>006</td>  
        <td>James</td>  
        <td>Canada</td>  
        <td>50000</td>  
      </tr>  

       <tr>  
        <td>007</td>  
        <td>Ronald</td>  
        <td>US</td>  
        <td>75000</td>  
      </tr>  
      <tr>  
        <td>008</td>  
        <td>Mike</td>  
        <td>Belgium</td>  
        <td>100000</td>  
      </tr>  
    </tbody>  
  </table>  
  </div>
</body>  

</html>  

https is secured connection.In your case you are using http in http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js which may be the source of the problem https是安全连接。在您的情况下,您正在http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js中使用http ,这可能是问题的根源

 $(document).ready(function() { $('#myTable').DataTable(); }); 
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script> <body style="margin:20px auto"> <table id="myTable" class="table table-striped"> <thead> <tr> <th>ENO</th> <th>EMPName</th> <th>Country</th> <th>Salary</th> </tr> </thead> <tbody> <tr> <td>001</td> <td>Anusha</td> <td>India</td> <td>10000</td> </tr> <tr> <td>002</td> <td>Charles</td> <td>United Kingdom</td> <td>28000</td> </tr> <tr> <td>003</td> <td>Sravani</td> <td>Australia</td> <td>7000</td> </tr> <tr> <td>004</td> <td>Amar</td> <td>India</td> <td>18000</td> </tr> <tr> <td>005</td> <td>Lakshmi</td> <td>India</td> <td>12000</td> </tr> <tr> <td>006</td> <td>James</td> <td>Canada</td> <td>50000</td> </tr> <tr> <td>007</td> <td>Ronald</td> <td>US</td> <td>75000</td> </tr> <tr> <td>008</td> <td>Mike</td> <td>Belgium</td> <td>100000</td> </tr> </tbody> </table> </div> 

@Philip Tenn, I have checked the code with and without https. @Philip Tenn,我检查了是否带有https的代码。 But I have no any issue with your code, its working fine. 但是我对您的代码没有任何问题,它的工作正常。

You have a </div> at the end of your table that shouldn't be there, but otherwise your code works fine... 在表的末尾有一个</div> ,不应在该处,否则代码可以正常工作...

 $(document).ready(function(){ $('#myTable').DataTable(); }); 
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Example of Employee Table with twitter bootstrap</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script> </head> <body style="margin:20px auto"> <table id="myTable" class="table table-striped" > <thead> <tr> <th>ENO</th> <th>EMPName</th> <th>Country</th> <th>Salary</th> </tr> </thead> <tbody> <tr> <td>001</td> <td>Anusha</td> <td>India</td> <td>10000</td> </tr> <tr> <td>002</td> <td>Charles</td> <td>United Kingdom</td> <td>28000</td> </tr> <tr> <td>003</td> <td>Sravani</td> <td>Australia</td> <td>7000</td> </tr> <tr> <td>004</td> <td>Amar</td> <td>India</td> <td>18000</td> </tr> <tr> <td>005</td> <td>Lakshmi</td> <td>India</td> <td>12000</td> </tr> <tr> <td>006</td> <td>James</td> <td>Canada</td> <td>50000</td> </tr> <tr> <td>007</td> <td>Ronald</td> <td>US</td> <td>75000</td> </tr> <tr> <td>008</td> <td>Mike</td> <td>Belgium</td> <td>100000</td> </tr> </tbody> </table> </body> </html> 

Perhaps there is something else on your page that is interfering with it? 也许您的页面上还有其他东西在干扰它?

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

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