为什么运行该函数后缺少某些元素?

如何解决为什么运行该函数后缺少某些元素?

我想做搜索引擎,但是我搜索了一些书后,我无法搜索到。它只返回零本书。

//data.js
// {
//   id: string | number,//   title: string,//   author: string,//   year: number,//   isComplete: boolean,// }

const STORAGE_KEY = "BOOKSHELF_APP";

let books = [];
let booksSearched = [];

function isStorageExist() /* boolean */ {
  return false // SO does not like localStorage
  if (typeof(Storage) === undefined) {
    alert("Your browser doesn't support web storage.");
    return false;
  }
  return true;
}

function saveData() {
  const parsed /* string */ = JSON.stringify(books);
  localStorage.setItem(STORAGE_KEY,parsed);
  document.dispatchEvent(new Event("ondatasaved"));
}

function loadDataFromStorage() {
  const serializedData /* string */ = localStorage.getItem(STORAGE_KEY);

  let data = JSON.parse(serializedData);

  if (data !== null)
    books = data;

  document.dispatchEvent(new Event("ondataloaded"));
}

function updateDataToStorage() {
  if (isStorageExist())
    saveData();
}

function composeBookObject(title,author,year,isCompleted) {
  return {
    id: +new Date(),title,isCompleted
  };
}

function findBookById(bookId) {

  for (book of books) {
    if (book.id === bookId)
      return book;
  }

  return null;
}

function searchBookByTitle(bookTitle) {

  for (book of books) {
    if (book.title === bookTitle) {
      return book;
    }
  }
  return null;
}

function findBookIndexById(bookId) {

  let index = 0
  for (book of books) {
    if (book.id === bookId)
      return index;

    index++;
  }

  return -1;
}

//dom.js
const UNFINISHED_BOOK_LIST_ID = 'unfinishedBookshelfList';
const FINISHED_BOOK_LIST_ID = 'finishedBookshelfList';
const BOOK_ITEMID = "itemId";

function makeBookList(data,isCompleted) {
  const container = document.createElement('article');
  container.classList.add('book_item');
  const textTitle = document.createElement('h3');
  textTitle.innerText = `Title: ${data}`;
  const textAuthor = document.createElement('p');
  textAuthor.innerText = `Author: ${author}`;
  const textYear = document.createElement('p');
  textYear.innerText = `Year: ${year}`;
  const textContainer = document.createElement('div');
  textContainer.append(textTitle,textAuthor,textYear);
  container.append(textContainer);
  const buttonContainer = document.createElement('div');
  buttonContainer.classList.add('action');

  if (isCompleted) {
    buttonContainer.append(
      createUndoButton(),createTrashButton()
    );
  } else {
    buttonContainer.append(
      createCheckButton(),createTrashButton()
    );
  }

  container.append(buttonContainer);
  return container;
}

function createButton(buttonTypeClass /* string */,eventListener /* Event */ ) {
  const button = document.createElement("button");
  button.classList.add(buttonTypeClass);
  button.addEventListener("click",function(event) {
    eventListener(event);
    event.stopPropagation();
  });

  if (buttonTypeClass == 'green1') {
    button.innerText = 'Belum Selesai Dibaca';
  } else if (buttonTypeClass == 'green2') {
    button.innerText = 'Selesai Dibaca';
  } else if (buttonTypeClass == 'red') {
    button.innerText = 'Hapus Buku';
  }

  return button;
}

function createUndoButton() {
  return createButton("green1",function(event) {
    // const button = document.querySelector('.green');
    // button.innerText = 'Belum Selesai Dibaca';
    undoBookFromCompleted(event.target.closest('.book_item'));
  });
}

function createTrashButton() {
  return createButton("red",function(event) {
    removeBookFromCompleted(event.target.closest(".book_item"));
  });
}

function createCheckButton() {
  return createButton("green2",function(event) {
    addBookToCompleted(event.target.closest('.book_item'));
  });
}

function addBook() {
  const unfinishedBookList = document.getElementById(UNFINISHED_BOOK_LIST_ID);
  const finishedBookList = document.getElementById(FINISHED_BOOK_LIST_ID);
  const textTitle = document.getElementById('inputBookTitle').value;
  const textAuthor = document.getElementById('inputBookAuthor').value;
  const textYear = document.getElementById('inputBookYear').value;
  const isCompleted = document.getElementById('inputBookIsCompleted').checked;

  const book = makeBookList(textTitle,textYear,isCompleted);
  const bookObject = composeBookObject(textTitle,isCompleted);

  book[BOOK_ITEMID] = bookObject.id;
  books.push(bookObject);

  if (isCompleted) {
    finishedBookList.append(book);
  } else {
    unfinishedBookList.append(book);
  }

  updateDataToStorage();
}

function addBookToCompleted(bookElement /* HTMLELement */ ) {
  const listCompleted = document.getElementById(FINISHED_BOOK_LIST_ID);
  const bookTitle = bookElement.querySelector("h3").innerText;
  const bookAuthor = bookElement.querySelector("p:nth-of-type(1)").innerText;
  const bookYear = bookElement.querySelector("p:nth-of-type(2)").innerText;

  const newBook = makeBookList(bookTitle,bookAuthor,bookYear,true);

  const book = findBookById(bookElement[BOOK_ITEMID]);
  book.isCompleted = true;
  newBook[BOOK_ITEMID] = book.id;

  listCompleted.append(newBook);
  bookElement.remove();

  updateDataToStorage();
}

function removeBookFromCompleted(bookElement /* HTMLELement */ ) {

  const bookPosition = findBookIndexById(bookElement[BOOK_ITEMID]);
  books.splice(bookPosition,1);

  bookElement.remove();
  updateDataToStorage();
  document.dispatchEvent(new Event("onbookremoved"));
}

function undoBookFromCompleted(bookElement /* HTMLELement */ ) {
  const listUncompleted = document.getElementById(UNFINISHED_BOOK_LIST_ID);
  const bookTitle = bookElement.querySelector("h3").innerText;
  const bookAuthor = bookElement.querySelector("p:nth-of-type(1)").innerText;
  const bookYear = bookElement.querySelector("p:nth-of-type(2)").innerText;

  const newBook = makeBookList(bookTitle,false);

  const book = findBookById(bookElement[BOOK_ITEMID]);
  book.isCompleted = false;
  newBook[BOOK_ITEMID] = book.id;

  listUncompleted.append(newBook);
  bookElement.remove();

  updateDataToStorage();
}

function searchBooks(bookTitle) {
  // const bookShelf = document.querySelectorAll('.book_shelf');
  const unfinishedBookList = document.getElementById(UNFINISHED_BOOK_LIST_ID);
  const finishedBookList = document.getElementById(FINISHED_BOOK_LIST_ID);
  const bookSearchedObject = searchBookByTitle(bookTitle);
  booksSearched.push(bookSearchedObject);
  // unfinishedBookList.childElement.remove();
  // finishedBookList.childElement.remove();
  const bookSearched = makeBookList(bookSearchedObject.title,bookSearchedObject.author,bookSearchedObject.year);

  if (bookSearched.isCompleted) {
    finishedBookList.append(bookSearched);
  } else {
    unfinishedBookList.append(bookSearched);
  }

  updateDataToStorage();
}

function refreshDataFromBooks() {
  const listUncompleted = document.getElementById(UNFINISHED_BOOK_LIST_ID);
  let listCompleted = document.getElementById(FINISHED_BOOK_LIST_ID);

  for (book of books) {
    const newBook = makeBookList(book.title,book.author,book.year,book.isCompleted);
    newBook[BOOK_ITEMID] = book.id;

    if (book.isCompleted) {
      listCompleted.append(newBook);
    } else {
      listUncompleted.append(newBook);
    }
  }
}

//script.js
document.addEventListener("DOMContentLoaded",function() {

  const submitForm /* HTMLFormElement */ = document.getElementById("inputBook");
  submitForm.addEventListener("submit",function(event) {
    event.preventDefault();
    addBook();
  });

  const searchButton = document.getElementById('searchSubmit');
  searchButton.addEventListener('click',function() {
    event.preventDefault();
    console.log('ok');
    const bookList = document.querySelectorAll('.book_list article');
    bookList.forEach(list => list.remove());
    const searchBookTitleValue = document.getElementById('searchBookTitle').value;
    searchBooks(searchBookTitleValue);
  });

  if (isStorageExist()) {
    loadDataFromStorage();
  }
});

document.addEventListener("ondatasaved",() => {
  console.log("Data has been saved.");
});

document.addEventListener("ondataloaded",() => {
  refreshDataFromBooks();
  alert('Welcome back!');
});

document.addEventListener("onbookremoved",() => {
  alert('Your book has removed from the list.');
});
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

body,input,button {
  font-family: 'Open Sans',sans-serif;
}

input,button {
  font-size: 16px;
}

.head_bar {
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: cornflowerblue;
  color: white;
}

main {
  max-width: 800px;
  width: 80%;
  margin: 0 auto;
  padding: 16px;
}

.input_section {
  display: flex;
  flex-direction: column;
  padding: 16px;
  border: 1px solid black;
  border-radius: 10px;
}

.input_section>h2 {
  text-align: center;
  color: cornflowerblue;
}

.input_section>form>.input {
  margin: 8px 0;
}

.input_section>form>button {
  background-color: cornflowerblue;
  color: white;
  border: 0;
  border-radius: 5px;
  display: block;
  width: 100%;
  padding: 8px;
  cursor: pointer;
}

.input_section>form>button>span {
  font-weight: bold;
}

.input_section>form>.input>input {
  display: block;
  width: 100%;
  padding: 8px;
  border-radius: 5px;
}

.input_section>form>.input>label {
  color: cornflowerblue;
  font-weight: bold;
}

.input_section>form>.input_inline {
  margin: 12px 0;
  display: flex;
  align-items: center;
}

.input_section>form>.input_inline>label {
  color: cornflowerblue;
  font-weight: bold;
  margin-right: 10px;
}

.search_section {
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  border: 1px solid black;
  border-radius: 10px;
}

.search_section>h2 {
  color: cornflowerblue;
}

.search_section>form {
  padding: 16px;
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr 0.5fr;
  grid-gap: 10px;
}

.search_section>form>label {
  display: flex;
  align-items: center;
}

.search_section>form>input {
  padding: 5px;
  border-radius: 5px;
}

.search_section>form>button {
  background-color: cornflowerblue;
  color: white;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}

.book_shelf {
  margin: 16px 0 0 0;
  border: 1px solid black;
  padding: 16px;
  border-radius: 10px;
}

.book_shelf>h2 {
  color: cornflowerblue;
}

.book_shelf>.book_list {
  padding: 16px;
}

.book_shelf>.book_list>.book_item {
  height: auto;
  padding: 8px 16px 16px 16px;
  border: 1px solid black;
  border-radius: 5px;
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
}

.book_item>.action {
  width: auto;
  height: 30px;
  margin: auto 5px;
  border-radius: 10%;
  display: flex;
  place-content: center;
  flex-basis: 1;
  gap: 5px
}

.book_shelf>.book_list>.book_item>h3,p {
  margin: 8px 0;
}

.book_shelf>.book_list>.book_item>.action>button {
  border: 0;
  padding: 5px;
  margin: 0 5px 0 0;
  border-radius: 5px;
  cursor: pointer;
  /* }

.green1,.green2,.red { */
  display: flex;
  align-items: center;
  /* place-content: center; */
}

.book_shelf>.book_list>.book_item>.action>.green1,.book_shelf>.book_list>.book_item>.action>.green2 {
  background-color: darkgreen;
  color: white;
}

.book_shelf>.book_list>.book_item>.action>.red {
  background-color: darkred;
  color: white;
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Bookshelf Apps</title>
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700;800&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <header class="head_bar">
    <h1 class="head_bar__title">Bookshelf Apps</h1>
  </header>
  <main>
    <section class="input_section">
      <h2>Input New Book</h2>
      <form id="inputBook">
        <div class="input">
          <label for="inputBookTitle">Title</label>
          <input id="inputBookTitle" type="text" required>
        </div>
        <div class="input">
          <label for="inputBookAuthor">Author</label>
          <input id="inputBookAuthor" type="text" required>
        </div>
        <div class="input">
          <label for="inputBookYear">Year</label>
          <input id="inputBookYear" type="number" required>
        </div>
        <div class="input_inline">
          <label for="inputBookIsCompleted">Finished Reading</label>
          <input id="inputBookIsCompleted" type="checkbox">
        </div>
        <button id="bookSubmit" type="submit">Input Your Book To Bookshelf <span>Unfinished Reading</span></button>
      </form>
    </section>

    <section class="search_section">
      <h2>Search Book</h2>
      <form id="searchBook">
        <label for="searchBookTitle">Title</label>
        <input id="searchBookTitle" type="text">
        <button id="searchSubmit" type="submit">Search</button>
      </form>
    </section>

    <section class="book_shelf">
      <h2>Unfinished Reading</h2>

      <div id="unfinishedBookshelfList" class="book_list">

      </div>
    </section>

    <section class="book_shelf">
      <h2>Selesai dibaca</h2>

      <div id="finishedBookshelfList" class="book_list">

      </div>
    </section>
  </main>
  <script src="js/data.js"></script>
  <script src="js/dom.js"></script>
  <script src="js/script.js"></script>
</body>

</html>

已编辑:我需要触发 onbookremoved 事件以显示警报。但是在我点击了从完成中移除书籍的按钮后,警报没有出现。

dom.js

function removeBookFromCompleted(bookElement /* HTMLELement */) {

    const bookPosition = findBookIndexById(bookElement[BOOK_ITEMID]);
    books.splice(bookPosition,1);

    bookElement.remove();
    updateDataToStorage();
    document.dispatchEvent(new Event("onbookremoved"));
}

script.js

document.addEventListener("onbookremoved",() => {
  alert('Your book has removed from the list.');
});

解决方法

您的 booklist.remove 擦除了列表而不是文章

  const bookList = document.querySelectorAll('.book_list article');

我也加了

 if (book.title.toLowerCase() === bookTitle.toLowerCase()) {

您还有其他几个问题

if (book.isCompleted) { // should be bookSearched.isCompleted
    finishedBookList.append(bookSearched);
} else {
    unfinishedBookList.append(bookSearched);
}

//data.js
// {
//   id: string | number,//   title: string,//   author: string,//   year: number,//   isComplete: boolean,// }

const STORAGE_KEY = "BOOKSHELF_APP";

let books = [];
let booksSearched = [];

function isStorageExist() /* boolean */ {
  return false // SO does not like localStorage
  if (typeof(Storage) === undefined) {
    alert("Your browser doesn't support web storage.");
    return false;
  }
  return true;
}

function saveData() {
  const parsed /* string */ = JSON.stringify(books);
  localStorage.setItem(STORAGE_KEY,parsed);
  document.dispatchEvent(new Event("ondatasaved"));
}

function loadDataFromStorage() {
  const serializedData /* string */ = localStorage.getItem(STORAGE_KEY);

  let data = JSON.parse(serializedData);

  if (data !== null)
    books = data;

  document.dispatchEvent(new Event("ondataloaded"));
}

function updateDataToStorage() {
  if (isStorageExist())
    saveData();
}

function composeBookObject(title,author,year,isCompleted) {
  return {
    id: +new Date(),title,isCompleted
  };
}

function findBookById(bookId) {

  for (book of books) {
    if (book.id === bookId)
      return book;
  }

  return null;
}

function searchBookByTitle(bookTitle) {
  console.log(bookTitle,books)
  for (book of books) {
    if (book.title.toLowerCase() === bookTitle.toLowerCase()) {
      return book;
    }
  }
  return null;
}

function findBookIndexById(bookId) {

  let index = 0
  for (book of books) {
    if (book.id === bookId)
      return index;

    index++;
  }

  return -1;
}

//dom.js
const UNFINISHED_BOOK_LIST_ID = 'unfinishedBookshelfList';
const FINISHED_BOOK_LIST_ID = 'finishedBookshelfList';
const BOOK_ITEMID = "itemId";

function makeBookList(data,isCompleted) {
  const container = document.createElement('article');
  container.classList.add('book_item');
  const textTitle = document.createElement('h3');
  textTitle.innerText = `Title: ${data}`;
  const textAuthor = document.createElement('p');
  textAuthor.innerText = `Author: ${author}`;
  const textYear = document.createElement('p');
  textYear.innerText = `Year: ${year}`;
  const textContainer = document.createElement('div');
  textContainer.append(textTitle,textAuthor,textYear);
  container.append(textContainer);
  const buttonContainer = document.createElement('div');
  buttonContainer.classList.add('action');

  if (isCompleted) {
    buttonContainer.append(
      createUndoButton(),createTrashButton()
    );
  } else {
    buttonContainer.append(
      createCheckButton(),createTrashButton()
    );
  }

  container.append(buttonContainer);
  return container;
}

function createButton(buttonTypeClass /* string */,eventListener /* Event */ ) {
  const button = document.createElement("button");
  button.classList.add(buttonTypeClass);
  button.addEventListener("click",function(event) {
    eventListener(event);
    event.stopPropagation();
  });

  if (buttonTypeClass == 'green1') {
    button.innerText = 'Belum Selesai Dibaca';
  } else if (buttonTypeClass == 'green2') {
    button.innerText = 'Selesai Dibaca';
  } else if (buttonTypeClass == 'red') {
    button.innerText = 'Hapus Buku';
  }

  return button;
}

function createUndoButton() {
  return createButton("green1",function(event) {
    // const button = document.querySelector('.green');
    // button.innerText = 'Belum Selesai Dibaca';
    undoBookFromCompleted(event.target.closest('.book_item'));
  });
}

function createTrashButton() {
  return createButton("red",function(event) {
    removeBookFromCompleted(event.target.closest(".book_item"));
  });
}

function createCheckButton() {
  return createButton("green2",function(event) {
    addBookToCompleted(event.target.closest('.book_item'));
  });
}

function addBook() {
  const unfinishedBookList = document.getElementById(UNFINISHED_BOOK_LIST_ID);
  const finishedBookList = document.getElementById(FINISHED_BOOK_LIST_ID);
  const textTitle = document.getElementById('inputBookTitle').value;
  const textAuthor = document.getElementById('inputBookAuthor').value;
  const textYear = document.getElementById('inputBookYear').value;
  const isCompleted = document.getElementById('inputBookIsCompleted').checked;

  const book = makeBookList(textTitle,textYear,isCompleted);
  const bookObject = composeBookObject(textTitle,isCompleted);

  book[BOOK_ITEMID] = bookObject.id;
  books.push(bookObject);

  if (isCompleted) {
    finishedBookList.append(book);
  } else {
    unfinishedBookList.append(book);
  }

  updateDataToStorage();
}

function addBookToCompleted(bookElement /* HTMLELement */ ) {
  const listCompleted = document.getElementById(FINISHED_BOOK_LIST_ID);
  const bookTitle = bookElement.querySelector("h3").innerText;
  const bookAuthor = bookElement.querySelector("p:nth-of-type(1)").innerText;
  const bookYear = bookElement.querySelector("p:nth-of-type(2)").innerText;

  const newBook = makeBookList(bookTitle,bookAuthor,bookYear,true);

  const book = findBookById(bookElement[BOOK_ITEMID]);
  book.isCompleted = true;
  newBook[BOOK_ITEMID] = book.id;

  listCompleted.append(newBook);
  bookElement.remove();

  updateDataToStorage();
}

function removeBookFromCompleted(bookElement /* HTMLELement */ ) {

  const bookPosition = findBookIndexById(bookElement[BOOK_ITEMID]);
  books.splice(bookPosition,1);

  bookElement.remove();
  updateDataToStorage();
}

function undoBookFromCompleted(bookElement /* HTMLELement */ ) {
  const listUncompleted = document.getElementById(UNFINISHED_BOOK_LIST_ID);
  const bookTitle = bookElement.querySelector("h3").innerText;
  const bookAuthor = bookElement.querySelector("p:nth-of-type(1)").innerText;
  const bookYear = bookElement.querySelector("p:nth-of-type(2)").innerText;

  const newBook = makeBookList(bookTitle,false);

  const book = findBookById(bookElement[BOOK_ITEMID]);
  book.isCompleted = false;
  newBook[BOOK_ITEMID] = book.id;

  listUncompleted.append(newBook);
  bookElement.remove();

  updateDataToStorage();
}

function searchBooks(bookTitle) {
  // const bookShelf = document.querySelectorAll('.book_shelf');
  const unfinishedBookList = document.getElementById(UNFINISHED_BOOK_LIST_ID);
  const finishedBookList = document.getElementById(FINISHED_BOOK_LIST_ID);
  const bookSearchedObject = searchBookByTitle(bookTitle) || {
    title: "na",author: "na",year: "na"
  };
  booksSearched.push(bookSearchedObject);
  // unfinishedBookList.childElement.remove();
  // finishedBookList.childElement.remove();
  const bookSearched = makeBookList(bookSearchedObject.title,bookSearchedObject.author,bookSearchedObject.year);
  // const bookElement = document.querySelectorAll('.book_item');
  // if(bookShelf !== null) {



  if (bookSearched.isCompleted) {
    finishedBookList.append(bookSearched);
  } else {
    unfinishedBookList.append(bookSearched);
  }

  updateDataToStorage();

}

function refreshDataFromBooks() {
  const listUncompleted = document.getElementById(UNFINISHED_BOOK_LIST_ID);
  let listCompleted = document.getElementById(FINISHED_BOOK_LIST_ID);

  for (book of books) {
    const newBook = makeBookList(book.title,book.author,book.year,book.isCompleted);
    newBook[BOOK_ITEMID] = book.id;

    if (book.isCompleted) {
      listCompleted.append(newBook);
    } else {
      listUncompleted.append(newBook);
    }
  }
}

//script.js
document.addEventListener("DOMContentLoaded",function() {

  const submitForm /* HTMLFormElement */ = document.getElementById("inputBook");
  submitForm.addEventListener("submit",function(event) {
    event.preventDefault();
    addBook();
  });

  const searchButton = document.getElementById('searchSubmit');
  searchButton.addEventListener('click',function() {
    event.preventDefault();
    console.log('ok');
    const bookList = document.querySelectorAll('.book_list article'); // changed
    bookList.forEach(list => list.remove());
    const searchBookTitleValue = document.getElementById('searchBookTitle').value;
    searchBooks(searchBookTitleValue);
  });

  if (isStorageExist()) {
    loadDataFromStorage();
  }
});

document.addEventListener("ondatasaved",() => {
  console.log("Data has been saved.");
});

document.addEventListener("ondataloaded",() => {
  refreshDataFromBooks();
  alert('Welcome back!');
});
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

body,input,button {
  font-family: 'Open Sans',sans-serif;
}

input,button {
  font-size: 16px;
}

.head_bar {
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: cornflowerblue;
  color: white;
}

main {
  max-width: 800px;
  width: 80%;
  margin: 0 auto;
  padding: 16px;
}

.input_section {
  display: flex;
  flex-direction: column;
  padding: 16px;
  border: 1px solid black;
  border-radius: 10px;
}

.input_section>h2 {
  text-align: center;
  color: cornflowerblue;
}

.input_section>form>.input {
  margin: 8px 0;
}

.input_section>form>button {
  background-color: cornflowerblue;
  color: white;
  border: 0;
  border-radius: 5px;
  display: block;
  width: 100%;
  padding: 8px;
  cursor: pointer;
}

.input_section>form>button>span {
  font-weight: bold;
}

.input_section>form>.input>input {
  display: block;
  width: 100%;
  padding: 8px;
  border-radius: 5px;
}

.input_section>form>.input>label {
  color: cornflowerblue;
  font-weight: bold;
}

.input_section>form>.input_inline {
  margin: 12px 0;
  display: flex;
  align-items: center;
}

.input_section>form>.input_inline>label {
  color: cornflowerblue;
  font-weight: bold;
  margin-right: 10px;
}

.search_section {
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  border: 1px solid black;
  border-radius: 10px;
}

.search_section>h2 {
  color: cornflowerblue;
}

.search_section>form {
  padding: 16px;
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr 0.5fr;
  grid-gap: 10px;
}

.search_section>form>label {
  display: flex;
  align-items: center;
}

.search_section>form>input {
  padding: 5px;
  border-radius: 5px;
}

.search_section>form>button {
  background-color: cornflowerblue;
  color: white;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}

.book_shelf {
  margin: 16px 0 0 0;
  border: 1px solid black;
  padding: 16px;
  border-radius: 10px;
}

.book_shelf>h2 {
  color: cornflowerblue;
}

.book_shelf>.book_list {
  padding: 16px;
}

.book_shelf>.book_list>.book_item {
  height: auto;
  padding: 8px 16px 16px 16px;
  border: 1px solid black;
  border-radius: 5px;
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
}

.book_item>.action {
  width: auto;
  height: 30px;
  margin: auto 5px;
  border-radius: 10%;
  display: flex;
  place-content: center;
  flex-basis: 1;
  gap: 5px
}

.book_shelf>.book_list>.book_item>h3,p {
  margin: 8px 0;
}

.book_shelf>.book_list>.book_item>.action>button {
  border: 0;
  padding: 5px;
  margin: 0 5px 0 0;
  border-radius: 5px;
  cursor: pointer;
  /* }

.green1,.green2,.red { */
  display: flex;
  align-items: center;
  /* place-content: center; */
}

.book_shelf>.book_list>.book_item>.action>.green1,.book_shelf>.book_list>.book_item>.action>.green2 {
  background-color: darkgreen;
  color: white;
}

.book_shelf>.book_list>.book_item>.action>.red {
  background-color: darkred;
  color: white;
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Bookshelf Apps</title>
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700;800&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <header class="head_bar">
    <h1 class="head_bar__title">Bookshelf Apps</h1>
  </header>
  <main>
    <section class="input_section">
      <h2>Input New Book</h2>
      <form id="inputBook">
        <div class="input">
          <label for="inputBookTitle">Title</label>
          <input id="inputBookTitle" type="text" required>
        </div>
        <div class="input">
          <label for="inputBookAuthor">Author</label>
          <input id="inputBookAuthor" type="text" required>
        </div>
        <div class="input">
          <label for="inputBookYear">Year</label>
          <input id="inputBookYear" type="number" required>
        </div>
        <div class="input_inline">
          <label for="inputBookIsCompleted">Finished Reading</label>
          <input id="inputBookIsCompleted" type="checkbox">
        </div>
        <button id="bookSubmit" type="submit">Input Your Book To Bookshelf <span>Unfinished Reading</span></button>
      </form>
    </section>

    <section class="search_section">
      <h2>Search Book</h2>
      <form id="searchBook">
        <label for="searchBookTitle">Title</label>
        <input id="searchBookTitle" type="text">
        <button id="searchSubmit" type="submit">Search</button>
      </form>
    </section>

    <section class="book_shelf">
      <h2>Unfinished Reading</h2>

      <div id="unfinishedBookshelfList" class="book_list">

      </div>
    </section>

    <section class="book_shelf">
      <h2>Selesai dibaca</h2>

      <div id="finishedBookshelfList" class="book_list">

      </div>
    </section>
  </main>
  <script src="js/data.js"></script>
  <script src="js/dom.js"></script>
  <script src="js/script.js"></script>
</body>

</html>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-