【发布时间】:2011-08-20 00:34:39
【问题描述】:
如果我在 JS 中有一个数组:
var myArray = [ 'text 1', 'text 2', 'text 3'];
我如何复制和 DIV 标记并设置所有数组值?,像这样:
<div>text 1</div>
<div>text 1</div>
<div>text 1</div>
非常感谢!
【问题讨论】:
标签: javascript arrays tags
如果我在 JS 中有一个数组:
var myArray = [ 'text 1', 'text 2', 'text 3'];
我如何复制和 DIV 标记并设置所有数组值?,像这样:
<div>text 1</div>
<div>text 1</div>
<div>text 1</div>
非常感谢!
【问题讨论】:
标签: javascript arrays tags
var divBlocks = myArray.map(function(x) { return "<div>" + x + "</div>"; });
【讨论】:
for(var key in myArray)
{
createDiv(key);
}
【讨论】: