我的代码中不断收到错误“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);
}
}
}
});
如何解决我的错误?