gpt4 book ai didi

javascript - 将 <input> 元素附加到 时,appendChild 为未定义

转载 作者:行者123 更新时间:2023-11-28 01:14:06 25 4
gpt4 key购买 nike

这里有人知道如何解决这个问题或遇到类似的问题吗?请告诉我我的代码是否写错了。先谢谢了。

<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);

关于javascript - 将 &lt;input&gt; 元素附加到 <td> 时,appendChild 为未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24050848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com