使用 while 循环在项目符号列表中显示的数组
array using a while loop to display in a bulleted list
我是 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;
var i = 0;
while(i<sLen){
...execution code goes here...
i++;
}
请查看此参考以了解有关 while 循环的更多信息while-loops-Javascript
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;
希望对你有所帮助
我是 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;
var i = 0;
while(i<sLen){
...execution code goes here...
i++;
}
请查看此参考以了解有关 while 循环的更多信息while-loops-Javascript
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;
希望对你有所帮助