我有一系列假设的JavaScript链接ID myArray = ["id1", "id2", "id3"];
如何创建每个链接元素并将其附加到html文档?
答案 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>"
});