如何修复.removeChild()不是函数

时间:2019-05-30 18:14:33

标签: javascript

我正在尝试仅删除在日记本中添加的最后一天,所以我尝试了removeChild(),但没有用。

let addDay = document.getElementById("addDay");
let tableHeader = document.getElementById("table-header");
let student = document.getElementsByClassName('student');
let newDay = document.getElementsByClassName('newDay');
let remDay = document.getElementById('remDay');
let newTableHeader = document.getElementsByClassName('newtableheader');

addDay.addEventListener('click', ()=> {
 let newTableHeader = document.createElement('th');
 newTableHeader.innerHTML ="09/03/2019";
 newTableHeader.setAttribute("class" , "newtableheader")
 tableHeader.appendChild(newTableHeader);

 for(let i = 0 ; i < student.length; i++){
    let newStudentsDay = document.createElement('td');
    newStudentsDay.innerHTML = "0";
    newStudentsDay.setAttribute("class","newDay");
    student[i].appendChild(newStudentsDay);
 }

 for(let i = 0; i < newDay.length; i++){
   newDay[i].addEventListener('click', ()=>{
   let grade = prompt('Enter students grade');
   if(!grade  || undefined || null || ""|| "string"){
    newDay[i].innerText = "";
      alert('please try again');
   }else if(grade === number){
   newDay[i].innerText = grade;
}
   })
}
});
remDay.addEventListener('click' , ()=> {
      tableHeader.removeChild(newTableHeader[0]);
      student.removeChild(NewDay[i]);
})

我创建了<th><td>元素,当我添加一些成绩时,我只想删除最后一天。

0 个答案:

没有答案