我的目標是獲取一個數組並顯示錶中的每個元素。我的問題是我覺得我錯過了這是我第二個月的js。任何人有想法?在javascript中顯示數組表格中的數組
var names = ["Ling, Mai","Johnson, Jim", "Zarnecki, Sabrina", "Jones, Chris","Jones, Aaron", "Swift, Geoffrey", "Xiong, Fong"];
console.log(names.length);// display array length
console.log(names);//display array
//onclick() show array in table
//src w3schools
function display() {
//-----------------------------------------------------
//src w3schools
var x = document.createElement("TABLE");
x.setAttribute("id", "myTable");
document.body.appendChild(x);
var y = document.createElement("TR");
y.setAttribute("id", "myTr");
document.getElementById("myTable").appendChild(y);
//-------------------------------------------------------
// //split up display to output each item in array in its own box
// // https://stackoverflow.com/questions/9329446/for-each-over-an-array-in-javascript
var index, len;
// // var a = ["a", "b", "c"];
for (index = 0, len = names.length; index < len; ++index) {
console.log(names[index]);
var t = document.createTextNode(names[index]);
z.appendChild(t);
}
var t = document.createTextNode("meow");
document.getElementById("myTr").appendChild(z);
console.log(z);
} //顯示結束()
哪裏是你的'功能顯示()'是爲了結束? – Aydin4ik
「z」在哪裏申報?它是什麼 ? –
它結束於底部。它更像是一個精神集團,然後是任何東西。 –