<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
用户名:<input type="text" placeholder="请输入用户名" /> <br />
<br />
密码: <input type="password" placeholder="请输入密码" />
<button>登录</button>
</body>
<script>
const input1 = document.querySelector("input:nth-of-type(1)");
const input2 = document.querySelector("input:nth-of-type(2)");
const button = document.querySelector("button");
button.onclick = function () {
if (!input1.value.trim()) {
alert("不能登录");
}
};
</script>
</html>
****