Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.


<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 num=2; function add(){ num++; var ot=document.getElementById('table'); var tbody=ot.getElementsByClassName("tbody")[0]; var otc=ot.childNodes[1]; var td1=document.getElementsByTagName("td"); var tt=document.createElement("tr"); var trs=otc.parentNode.appendChild(tt); 未捕获类型错误:未能在“节点”上执行“Append Child”:参数1不是“节点”类型。 otc.parentNode.appendChild('tr');      解析:appendChild()需要传入的是一个tr的对象,而不是tr的字符串. 正确如下: function render(){ for (let i=0; i<data.length; i++){ var data=xh00; let tr=document.createElement('tr'); tr.innerHTML='<tr><th>'+data[num]+'</tr></th>'; tbody.appendChild(data.join(',')); } }
    
换一种写法:
     function render(){
       var html=[]
       for (let i=0; i<data.length; i++){
       let template='<tr><th>'+data[num]+'</tr></th>';
       html.push(template);
        tr.innerHTML=html.join('');
       }
     }
} <script>

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM