0

我有一个由 Lunr.js 提供支持的带有基本单词搜索的小型静态站点。我有一个搜索字段,位于每个 HTML 页面的标题中。我使用的是假 json,因为我不需要 Jekyll

const fakeJSON = [
  {
    title: "Test",
    content:
      "Chocolate bar cupcake chocolate bar cake oat cake sweet roll chocolate cake chupa chups danish. Chocolate cake marshmallow cake cheesecake powder. Candy canes chocolate chupa chups liquorice donut chocolate cake apple pie cupcake soufflé. Halvah gingerbread powder cupcake apple pie chocolate cake. Halvah wafer liquorice sweet roll jelly tart soufflé croissant.  Ice cream macaroon lemon drops liquorice ice cream pastry. ",
    href: "test.html"
  }

搜索 html

    <div class="search-flex">
        <form id="search-form" name="searchForm" role="form" onsubmit="return false">
        <div class="search-wrapper">
            <div class="search-container">
              <i class="fa fa-search"></i>
              <input autocomplete="off" placeholder="" id="search" class="search-input" aria-label="Search site" type="text" name="q">
            </div>
         <div class="search-error hide-element"><span class="search-error-message"></span></div>
         </div>
    </form>
   <button id="clear-search-results-sidebar" class="button clear-search-results hide-element">Clear Search Results</button>
 </div>

这是 search.js 输出

function renderSearchResults(query, results) {
  clearSearchResults();
  updateSearchResults(query, results);
  showSearchResults();
  scrollToTop();
}

function showSearchResults() {
  document.querySelector(".search-results").classList.remove("hide-element");
  document.getElementById("site-search").classList.add("expanded");
  document
    .getElementById("clear-search-results-sidebar")
    .classList.remove("hide-element");
}

我希望结果重定向到 search.html 并吐出结果。

<div class="search-results"></div>
4

0 回答 0