简体   繁体   English

获取此错误 - 无法获取未定义或空引用的属性“mData”

[英]Getting this error - Unable to get property 'mData' of undefined or null reference

I am getting the below error when I use the jQuery data table. 当我使用jQuery数据表时,我收到以下错误。

Error: Unable to get property 'mData' of undefined or null reference 错误:无法获取未定义或空引用的属性“mData”

Code

<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">

<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.js"></script>

<script type="text/javascript">

    $(document).ready(function() {
           $('#empTable').DataTable();
    } );
</script>

<table id="empTable" class="display" width="100%">
    <tr>
        <th>Name</th>
        <th>Age</th>
        <th>Address</th>
    </tr>
    <tr>
        <td>AAAAA</td>
        <td>32</td>
        <td>Colombo</td>
    </tr>
    <tr>
        <td>BBBBB</td>
        <td>29</td>
        <td>Kandy</td>
    </tr>
</table>

Please suggest me how to fix this issue? 请建议我如何解决这个问题?

Your html structure is not proper, you need to have a thead element where the header is specified and the content should be in tbody . 你的html结构不正确,你需要有一个指定标题的thead元素,内容应该是tbody

 $(document).ready(function() { $('#empTable').DataTable(); }); 
 <script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.js"></script> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/css/jquery.dataTables.css" /> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/js/jquery.dataTables.js"></script> <table id="empTable" class="display" width="100%"> <thead> <tr> <th>Name</th> <th>Age</th> <th>Address</th> </tr> </thead> <tbody> <tr> <td>K.Senthuran</td> <td>32</td> <td>42nd Lane</td> </tr> <tr> <td>S.Senthuran</td> <td>29</td> <td>Hampden Lane</td> </tr> </tbody> </table> 

 $(document).ready(function() { $('#empTable').DataTable(); }); 
 <script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.js"></script> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/css/jquery.dataTables.css" /> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/js/jquery.dataTables.js"></script> <table id="empTable" class="display" width="100%"> <thead> <tr> <th>Name</th> <th>Age</th> <th>Address</th> </tr> </thead> <tbody> <tr> <td>K.Senthuran</td> <td>32</td> <td>42nd Lane</td> </tr> <tr> <td>S.Senthuran</td> <td>29</td> <td>Hampden Lane</td> </tr> </tbody> </table> 

HTML structures in the table needs to match. 表中的HTML结构需要匹配。 For instance, <th> tags in your <thead> with the <tr> 's in the <tbody> . 例如, <th> <thead> <th>标记与<tbody><tr> <tbody> That is, if in the table you expect 5 columns , there should be 5 <th> tags in the table head and 5 <tr> tags in the table body. 也就是说,如果在表中你期望有5列,那么表头中应该有5 <th>标签,表体中应该有5 <th> <tr>标签。

暂无
暂无

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

相关问题 无法获取未定义或空引用的属性“未定义” - Getting Unable to get property 'undefined' of undefined or null reference 我一直在“无法获取未定义或空引用的属性”长度” - I keep getting 'unable to get property 'length' of undefined or null reference' 混淆获取此错误提示器无法获取未定义或空引用的属性“检查” - Confusion Getting this Errorr Unable to get property 'checked' of undefined or null reference IE Javascript错误:无法获取未定义或空引用的属性“ 0” - IE Javascript Error: Unable to get property '0' of undefined or null reference JavaScript运行时错误:无法获取未定义或空引用的属性“选项” - JavaScript runtime error: Unable to get property 'options' of undefined or null reference JavaScript错误:无法获取未定义或空引用的属性“样式”? - JavaScript Error: Unable to get property 'style' of undefined or null reference? 错误:“无法获取未定义或空引用文件的属性&#39;content&#39; - Error:"Unable to get property 'content' of undefined or null reference file JavaScript运行时错误无法获取未定义或空引用的属性“值” - JavaScript runtime error Unable to get property 'value' of undefined or null reference Javascript返回类型错误“无法获取未定义或空引用的属性&#39;1&#39;” - Javascript Returning a Type Error “Unable to get property '1' of undefined or null reference” JavaScript运行时错误:无法获取未定义或空引用的属性“ top” - JavaScript runtime error: Unable to get property 'top' of undefined or null reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM