不断收到此错误:Uncaught TypeError: Cannot call method 'appendChild' of null main.js:24 makingMySelect main.js:24 (anonymous function) 这是代码:
window.addEventListener("DOMContentLoaded", function(){
function $(x){
var myElements = document.getElementById(x);
return myElements;
}
// create select field element and populate with options
function makingMySelect (){
var formTag = document.getElementsByTagName("form");// array
var selectLi = $("select");
var makeSelect = document.createElement("select");
makeSelect.setAttribute("id","peopleGoing");
for(i=0,j=reservePeopleGoing.length;i<j;i++){
var makeOption = document.createElement("option");
var optText = reservePeopleGoing[i];
makeOption.setAttribute("value", optText);
makeOption.innerHTML = optText;
makeSelect.appendChild(makeOption);
}
selectLi.appendChild(makeSelect);
}
var reservePeopleGoing = ["1","2","3","4","5"];
var placeToGo = ["Astrada's","AppleBees","Chili's","Outback","O'Charleys"]
makingMySelect ();