我是Javascript的新手,我正在尝试使用While循环而不是For循环重新创建以下代码。我可以将它列入清单但不在无序列表中。任何帮助将不胜感激。
var middle = "Wayne";
var streets = ["Elm Street", "Sesame Street", "Coronation Street", "Jump
Street", "Wall Street"];
var sLen = streets.length;
var text = "<ul>";
for (i = 0; i < sLen; i++){
text += "<li>" + middle + " " + streets[i] + "</li>";
}
text += "</ul>";
document.getElementById("nameList").innerHTML = text;
答案 0 :(得分:0)
var i = 0;
while(i<sLen){
...execution code goes here...
i++;
}
请查看此参考,详细了解while循环while-loops-Javascript
答案 1 :(得分:0)
var middle = "Wayne";
var streets = ["Elm Street", "Sesame Street", "Coronation Street", "Jump
Street", "Wall Street"];
var sLen = streets.length;
var text = "<ul>";
while(sLen--) {
text += "<li>" + middle + " " + streets[sLen] + "</li>";
}
text += "</ul>";
document.getElementById("nameList").innerHTML = text;
我希望它会对你有所帮助。