jquery.min.js:2 Uncaught TypeError: Cannot set properties of null (setting 'onkeyup')

问题描述 投票:0回答:0

我的代码中不断收到错误“jquery.min.js:2 Uncaught TypeError: Cannot set properties of null (setting 'onkeyup')”。

Index.html:

<div class="search-box">
  <div class="row">
    <input
     type="text"
     class="form-control mb-3"
     placeholder="Search"
     id="input-box"
     autocomplete="off"/>
     <div class="result-box" id="result-box">
     </div>
  </div>
</div>

Script.js:

$(function () {
    const resultsBox = document.querySelector(".result-box");
    const inputBox = document.querySelector(".input-box");

    inputBox.onkeyup = function(){
      let result = [];
      let input = inputBox.value;

      if(input.length){
        result = availableKeywords.filter((keyword) =>{
           returnkeyword.toLowerCase().includes(input.toLowerCase());
        });
        console.log(result);
      }
    }
  }
});

如何解决我的错误?

javascript html jquery onkeyup
© www.soinside.com 2019 - 2024. All rights reserved.