var urlName=new Array("total","pub");
var query = window.location.search.substring(1);
for (var i=0;i<vars.length;i++) {
document.getElementById("'"+urlName[i]+"'").innerHTML = pair[i];
}
如何动态分配UrlNames?
答案 0 :(得分:1)
您不需要urlName[i]
周围的引号,因为它是一个字符串:
var urlName = ["total","pub"];
for (var i=0;i<urlName.length;i++) {
document.getElementById(urlName[i]).innerHTML = pair[i];
}