<input type="submit" value="Login"> 点击弹出提示
时间: 2023-07-19 13:43:33 浏览: 53
好的,可以通过 JavaScript 实现点击登录按钮后弹出提示框的效果。以下是修改后的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
form {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
margin: 50px auto;
}
input[type=text], input[type=password] {
padding: 10px;
margin: 10px 0;
border: none;
border-radius: 5px;
background-color: #f2f2f2;
width: 100%;
}
input[type=submit] {
background-color: #4CAF50;
color: #fff;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
width: 100%;
}
input[type=submit]:hover {
background-color: #45a049;
}
</style>
<script>
function showLoginResult() {
// 弹出提示框
alert("Login successful!");
}
</script>
</head>
<body>
<form>
<h2>Login</h2>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="Login" onclick="showLoginResult(); return false;">
</form>
</body>
</html>
```
在以上代码中,我们添加了一个 JavaScript 函数 `showLoginResult()`,用于弹出登录成功的提示框。在登录按钮的 HTML 代码中,我们添加了 `onclick` 属性,当登录按钮被点击时,该属性的值会被执行,即调用 `showLoginResult()` 函数。同时,我们在 `onclick` 属性值的最后添加了 `return false;`,用于阻止表单的默认提交行为,避免页面刷新。