我一直無(wú)法顯示輸入值。它顯示未定義的標(biāo)題和作者,并在我指定數(shù)字時(shí)完全忽略頁(yè)面。鏈接 JS 小提琴:https : //jsfiddle.net/u3cb96x5/這是我嘗試過(guò)的 - 我創(chuàng)建了一個(gè)名為 addBookToLibrary 的函數(shù)來(lái)查詢 DOM 值并創(chuàng)建新的 Book 對(duì)象,但由于函數(shù)范圍,我將無(wú)法訪問(wèn)這些變量。// Variablesconst addBook = document.querySelector("#add");// const remove = document.querySelector("#remove");let library = [];// Event ListenersaddBook.addEventListener("click", render);class Book { constructor(title, author, pages, isRead) { this.title = title; this.author = author; this.pages = pages; this.isRead = isRead; }}function addBookToLibrary() { let authorOfBook = document.querySelector("#author").value; let bookTitle = document.querySelector("#book-title").value; let numberOfPages = document.querySelector("#pages").value; let status = document.querySelector("#isRead").value; let newBook = new Book(bookTitle, authorOfBook, numberOfPages, status); library.push(newBook);}function render() { addBookToLibrary(); let table = document.querySelector("table"); let tr = document.createElement("tr"); table.appendChild(tr); tr.innerHTML = `<td>${this.title}</td> <td>${this.author}</td> <td>${this.pages}</td> <td><button class="table-buttons" id="not-read">Not Read</button></td> <td><button class="table-buttons" id="remove">Delete</button></td>`;}我希望它顯示未定義的指定輸入字段的值
如何在屏幕上顯示輸入值?
慕斯709654
2021-08-20 19:34:54