我想在用戶在提示符中輸入'exit'後向頁面添加項目符號列表;該清單不應包含「退出」一詞。我能夠使用document.write得到完整的列表,但是這包括'退出'並擺脫了我的頁面格式。我很確定我需要使用innerHTML,但是當我這樣做時,我得到的是沒有任何數組項目的頁面。任何幫助是極大的讚賞。在Javascript中使用innerHTML的Array項目的無序列表
<html>
<head>
<img src="http://profperry.com/Classes20/JavaScript/lordoftherings.png" />
<title>Javascript Test</title>
<script>
function askMe() {
var fav_characterList = new Array();
i = 0;
var fav_character = "";
while(fav_character != 'exit'){
fav_character = prompt("Who's your favorite Lord of the Rings character\n\n Enter 'exit' to stop prompting", "");
fav_characterList[i] = fav_character;
i++;
}
n = (fav_characterList.length);
for(i = 0; i <= (n-1); i++){
var list = fav_characterList[i];
var MyList = getElementById('results');
MyList.innerHTML = "<li>"+list+"</li>";
}
}
</script>
</head>
<body onload="askMe()">
<ul>
<div id="results">
</div>
</ul>
<br/>
<br/>
</body>
非常感謝!那竅門 – user981572
kkkk ........ :) – mithunsatheesh