index.js:12未被捕获的TypeError:无法在index.js:12上读取null的属性“值”
这是我的代码(html):
<html>
<head>
<title>Test</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
<link href="stylesheet.css" rel="stylesheet">
<script src="index.js"></script>
</head>
<body>
<h1 id="title">Test</h1>
<hr>
<h1 id="login_title">Login to access website</h1>
<label id="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" id="username" required>
<label id="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" id="password" required>
<button id="submit" type="submit">Login</button>
</body>
(js)
console.log(document.getElementById("password").value)
当然,错误是无法读取null的属性“值”