document.getElementById("searchbutton").onclick = function(){
var input1 = document.getElementById("searchbar").value;
console.log(input1);
}
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="shortcut icon" type="image/png" href="imgs/logo.png">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<!--Imports-->
<link rel="stylesheet" type="text/css" href="Style.css">
<script src="JavaScript.js"></script>
<!--code-->
<div style="text-align: center;">
<img src="imgs/logo.png" class="logo" alt="Image">
<input type="search" placeholder=" search" id="searchbar">
<button type="button" id="searchbutton">
<p>Search</p>
</button>
</div>
</html>
我的错误是在 js 代码上:Uncaught TypeError: Cannot set property 'onclick' of null at JavaScript.js:2