简单的JavaScript将数组链接ID附加到html doc?

时间:2014-04-23 19:52:41

标签: javascript

我有一系列假设的JavaScript链接ID myArray = ["id1", "id2", "id3"]; 如何创建每个链接元素并将其附加到html文档?

1 个答案:

答案 0 :(得分:0)

var myArray = ["id1", "id2", "id3"];
var container = document.getElementById('container');
myArray.forEach(function(id){
  container.innerHTML =  container.innerHTML + "<a href=\""+id+"\">"+id+"</a>"
}); 

http://jsfiddle.net/suwJr/