js操做DOM在父元素中的结尾添加子节点注意

impressionHtml=`<img src=${value} alt=""/>`;
document.getElementById("wrapper").appendChild(impressionHtml);

js向父元素wrapper中的末尾添加 定义好的html,报错:html

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

在stackoverflow上找到很好的一个解释:jquery

 

 

因此js是不能直接传入字符串的,可是jquery的append能够直接传入html字符串。app

相关文章
相关标签/搜索