【发布时间】:2019-03-16 00:28:34
【问题描述】:
我正在使用从 codepen 获得的这段代码将 div 节点附加到父 div 并且它工作正常。
var el = document.getElementById('items'),
elChild = document.createElement("div");
elChild.innerHTML = '<div class="product"><a href="product1.html"><img src="images/product1.png" alt="product1" /></a></div>'
el.appendChild(elChild);
如何添加更多 div 元素,因为我尝试按照下面的代码添加它们但失败了,提前致谢
var el = document.getElementById('items'),
elChild = document.createElement("div");
elChild.innerHTML = '<div class="product"><a href="product1.html"><img src="images/product1.png" alt="product1" /></a></div>'
'<div class="product"><a href="product2.html"><img src="images/product2.png" alt="product2" /></a></div>'
'<div class="product"><a href="product3.html"><img src="images/product3.png" alt="product3" /></a></div>'
el.appendChild(elChild);
【问题讨论】:
-
使用
+连接字符串
标签: javascript append