第一个基础版的HTML网站
html<!DOCTYPE html><html><head> <title>登录页面</title></head><body> <form id="loginForm"> <bel for="username">用户名:</bel><br> <input type="text" id="username" name="username"><br> <bel for="password">密码:</bel><br> <input type="password" id="password" name="password"><br> <input type="submit" value="登录"> </form></body></html>CSS (在 styles.css 文件中)cssbody { font-family: Arial, sans-serif; padding: 20px;}form { margin-top: 20px;}bel { dispy: block; margin-bottom: 10px;}input[type="text"], input[type="password"] { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px;}input[type="submit"] { background-color: #008CBA; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer;}JavaScript (在 script.js 文件中)javascriptdot.getElementById("loginForm").addEventListener("submit", fu) { event.preventDefault(); // 阻止表单默认提交行为 var username = dot.getElementById("username").value; var password = dot.getElementById("password").value; if(username === "" || password === "") { alert("用户名或密码不能为空!"); return false; } alert("登录成功!");});