Uncaught TypeError: Cannot read property 'cells' of undefined

Posted aivnfjgj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Uncaught TypeError: Cannot read property 'cells' of undefined相关的知识,希望对你有一定的参考价值。

<table border="1" width="50%" id="table">
        <tr>
          <th>学号</th>
          <th>姓名</th>
          <th>操作</th>
        </tr>
        <tr>
          <td>xh001</td>
          <td>阮雌</td>
          <td><a href="javascript:;" onclick="delete(this)">删除</a></td>   <!--在删除按钮上添加点击事件  -->
        </tr>
        <tr>
           <td>xh002</td>
           <td>刘赫</td>
           <td><a href="javascript:;" onclick="delete(this)" >删除</a></td>   <!--在删除按钮上添加点击事件  -->
        </tr>
    </table>
<script>
          var tr=document.getElementsByTagName("tr");
          var td=document.getElementsByTagName("td");
         for(var i=0;i<tr.length;i++){
              var n=1;
                n++;
             var k=0;
             
             var cells=tr[i+n].cells;
             
             var length=tr[i+n].cells.length;
             while(k<cells.length){
                 k++;
             }
//            tr[i+n].cells.innerhtml+="xh00";
            console.log(tr[i+n].cells.length)
         }
     }
</script>
报错:没有找到cells元素,这里是个执行顺序写错了,把while循环写在cells上面,问题得到解决。

  

以上是关于Uncaught TypeError: Cannot read property 'cells' of undefined的主要内容,如果未能解决你的问题,请参考以下文章

如何解决问题:Uncaught (in promise) TypeError: promisify is not a function?

Uncaught TypeError

Uncaught TypeError: Cannot redefine property: $router

Uncaught TypeError: o.block is not a function

Laravel 5.1 和 Vue.js - 21678 Uncaught (in promise) TypeError: Cannot read property 'data' of null

jQuery Post blob 对象给出 Uncaught TypeError: Illegal invocation