亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在屏幕上顯示輸入值?

如何在屏幕上顯示輸入值?

慕斯709654 2021-08-20 19:34:54
我一直無法顯示輸入值。它顯示未定義的標題和作者,并在我指定數字時完全忽略頁面。鏈接 JS 小提琴:https : //jsfiddle.net/u3cb96x5/這是我嘗試過的 - 我創建了一個名為 addBookToLibrary 的函數來查詢 DOM 值并創建新的 Book 對象,但由于函數范圍,我將無法訪問這些變量。// 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>`;}我希望它顯示未定義的指定輸入字段的值
查看完整描述

3 回答

?
BIG陽

TA貢獻1859條經驗 獲得超6個贊

使用數組而不是“this”


let book = library[library.length - 1];

<td>${book.title}</td>


查看完整回答
反對 回復 2021-08-20
  • 3 回答
  • 0 關注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號