我想通过点击按钮创建 4 个 div
元素。
请参阅,this fiddle对于我当前的实现。
在当前 View 中,新元素添加到彼此的底部。
我的问题是我不知道如何将它们并排放置。
我想要 4 个 div
元素(两个在顶部,两个在底部,正方形)
那是我的代码的一部分:
var box = document.getElementById('box'),
template = box.getElementsByTagName('div'),
template = template[0];
submit1.onclick = function () {
var new_field = template.cloneNode(true);
box.appendChild(new_field);
return false;
};
我该怎么做?
最佳答案
因为div的
默认display
是block
所以需要加上
display:inline-block;// add this to your div style
CSS
div { margin:1em;display:inline-block; }
关于javascript - 通过单击按钮添加多个 div 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21984531/