我试图返回每个元素前面带有索引的数组,并删除每个元素后面的逗号。我能够将每个元素返回到一个新行,但push()仍然无法获得编号列表。我试过在我的 js 中也使用<li>and 。我在这里错过了什么?<ol><div>
// TODO keep the student list state in a global list
var roster = new Array("");
function addStudent() {
// TODO lookup the user entered text
var newStudent = document.getElementById("student").value;
// TODO store the new student name in global list
roster.push("<div>" + newStudent + "</div>");
// TODO render the entire list into the output div
roster.innerHTML = roster.join('');
document.getElementById("output").innerHTML = "Student List" + roster;
return false;
}
function init() {
// TODO register the onsubmit for 'theForm' to use addStudent
if (document && document.getElementById) {
document.getElementById('theForm').onsubmit = addStudent;
}
}
window.onload = init;
<form action="#" method="post" id="theForm" novalidate>
<fieldset>
<legend>Enter a student name to add to the roster</legend>
<div><label for="student">Student Name</label><input type="text" name="student" id="student"></div>
<input type="submit" value="Add to Roster" id="submit">
<div id="output"></div>
</fieldset>
</form>
<!-- <script src="js/students.js"></script> -->
慕尼黑8549860
ITMISS
眼眸繁星
相关分类