0
這是JavaScript。該選擇具有'counties
'的id
。如何將下拉列表中的值推送到數組並將該數組添加到表中?
該表格將被插入名爲'up_bottom
'的div
中。
var leagueArray = [];
function addTeams() {
var county=document.getElementById("counties");
var val = county.options[county.selectedIndex].value;
leagueArray.push(val);
function display() {
var table = document.createElement("table");
for (var i=0; i<leagueArray.length; i++) {
var row = table.insertRow();
for (var j=0; j<leagueArray[i].length; j++) {
var cell = row.insertCell();
cell.appendChild(document.createTextNode(leagueArray[i]));
}
}
var tableDiv = document.getElementById("up_bottom");
tableDiv.appendChild(table);
}
display();
}
而且?你是否在控制檯中發生錯誤?什麼似乎是問題? – Andy
Uncaught TypeError:無法讀取null屬性的'appendChild' – nedduff