如果我在JS數組:重複的標籤從Array
var myArray = [ 'text 1', 'text 2', 'text 3'];
我如何可以複製和DIV標籤,並設置所有的數組值?是這樣的:
<div>text 1</div>
<div>text 1</div>
<div>text 1</div>
非常感謝!
如果我在JS數組:重複的標籤從Array
var myArray = [ 'text 1', 'text 2', 'text 3'];
我如何可以複製和DIV標籤,並設置所有的數組值?是這樣的:
<div>text 1</div>
<div>text 1</div>
<div>text 1</div>
非常感謝!
var divBlocks = myArray.map(function(x) { return "<div>" + x + "</div>"; });
for(var key in myArray)
{
createDiv(key);
}
打交道時,我會認爲,在國家對對象的屬性迭代更加有用,並且使用更普遍支持的for循環或只是新的forEach操作會更好與一個數組。 – Gabriel
值得一提的是,某些瀏覽器不支持地圖,因此必須對其進行掃描。 – Gabriel