问题:Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'
原因:appendChild的参数为node节点,导致这样的问题说明当前的参数不是node,有可能是字符串。
解决:使用dom的方法创建一个标签
上代码
<div>
你好
</div>
<script>
let newhtml=document.createElement('h1');
newhtml.innerHTML='完成了'
document.querySelector('div').appendChild(newhtml)
</script>
博客指出执行appendChild方法时出现参数非Node类型的问题,原因可能是参数为字符串。解决办法是使用dom方法创建一个标签,并表示会给出代码示例。
1万+

被折叠的 条评论
为什么被折叠?



