繁体   English   中英

追加时未定义的appendChild <input> 元素 <td>

[英]appendChild of undefined when Append <input> element to <td>

这里有人知道如何解决此问题或有类似问题吗? 请告诉我代码是否写错了。 之前谢谢。

<script type='text/javascript'>

//Getting table by id
var table = document.getElementById(str);

//Creating New Row
var row = document.createElement("tr");

//Creating New TD
var td1 = document.createElement('td');

//Creating new input.
var newInput= document.createElement('input');
newInput.setAttribute('type', 'text');
newInput.setAttribute('class', 'quantity');

//Appending newInput to TD - Return Appendchild of undefined
td1.appenChild(newInput);

//Append td to tr
row.appendChild(td1);

//Append tr to table
table.children[0].appendChild(row);

</script>

您在函数名称中缺少dappenChild应该为appendChild

//Appending newInput to TD - Return Appendchild of undefined
td1.appendChild(newInput);

暂无
暂无

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

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