<input type="submit" style="position: relative;top: 30px;background-color: rgb(117, 117, 232);" type="submit" value="登录" size="30">,如何监听这个提交按钮
时间: 2023-07-21 12:01:09 浏览: 31
要监听提交按钮的点击事件,你可以使用JavaScript来实现。你可以为该按钮添加一个点击事件监听器,并在点击时执行相应的操作。以下是一个示例代码:
```javascript
// 获取提交按钮元素
var submitBtn = document.querySelector('input[type="submit"]');
// 添加点击事件监听器
submitBtn.addEventListener('click', function() {
// 在点击时执行的操作
// 可以在这里编写你想要执行的代码
});
```
在这个示例中,我们首先使用`querySelector`方法获取到提交按钮的元素,然后使用`addEventListener`方法为该按钮添加一个点击事件监听器。在监听器的回调函数中,你可以编写你想要执行的代码,例如验证表单数据、发送请求等。
相关问题
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>登录页面</title> <style> body { background-color: #f2f2f2; } .container { width: 400px; margin: 0 auto; margin-top: 100px; padding: 20px; background-color: #fff; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); } h2 { text-align: center; margin-bottom: 20px; } label { display: block; margin-bottom: 10px; } input[type="text"], input[type="password"] { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; } input[type="submit"] { width: 100%; padding: 10px; background-color: #4CAF50; color: #fff; border: none; border-radius: 5px; cursor: pointer; } input[type="submit"]:hover { background-color: #45a049; } </style> </head> <body> <div class="container"> <h2>登录</h2> <form action="login.php" method="POST"> <label for="username">用户名:</label> <input type="text" id="username" name="username" required> <label for="password">密码:</label> <input type="password" id="password" name="password" required> <input type="submit" value="登录"> </form> </div> </body> </html> 修改上述代码使背景颜色变为蓝色,点击登录后可以跳转到lianxiren.php
你可以通过修改代码中的CSS样式来实现背景颜色的变化和跳转功能。请尝试将以下代码替换到原有的代码中:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录页面</title>
<style>
body {
background-color: blue; /* 将背景颜色改为蓝色 */
}
.container {
width: 400px;
margin: 0 auto;
margin-top: 100px;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
h2 {
text-align: center;
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
input[type="submit"] {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h2>登录</h2>
<form action="lianxiren.php" method="POST"> <!-- 将 action 属性的值改为 lianxiren.php -->
<label for="username">用户名:</label>
<input type="text" id="username" name="username" required>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="登录">
</form>
</div>
</body>
</html>
```
这样修改后的代码将会使背景颜色变为蓝色,并且点击登录按钮后会跳转到 `lianxiren.php` 页面。
<!DOCTYPE html><html><head> <title>嵌入式设备登录</title> <link rel="stylesheet" type="text/css" href="style.css"></head><body> <div class="login-box"> <img src="background.jpg" class="background"> <h1>设备登录</h1> <form> <label for="username">用户名:</label> <input type="text" id="username" name="username" required> <label for="password">密码:</label> <input type="password" id="password" name="password" required> <input type="submit" value="登录"> </form> </div></body></html>body { background-color: #f2f2f2;}.login-box { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); background-color: #fff; padding: 50px; border-radius: 10px; box-shadow: 0 0 20px 0 rgba(0,0,0,0.2);}.background { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; filter: blur(5px);}h1 { margin: 0 0 30px; padding: 0; font-size: 28px; text-align: center; color: #333; text-shadow: 2px 2px 2px rgba(0,0,0,0.2);}form { display: flex; flex-direction: column;}label { margin-bottom: 10px; font-size: 18px; color: #333; text-shadow: 2px 2px 2px rgba(0,0,0,0.2);}input[type="text"], input[type="password"] { padding: 10px; border: none; border-radius: 5px; background-color: #f2f2f2; color: #333; box-shadow: inset 0 0 5px rgba(0,0,0,0.2);}input[type="submit"] { margin-top: 20px; padding: 10px; border: none; border-radius: 5px; background-color: #f90; background-image: linear-gradient(to bottom, #f90, #f60); color: #fff; font-size: 18px; cursor: pointer; box-shadow: 0 2px 2px rgba(0,0,0,0.2);}input[type="submit"]:hover { background-image: linear-gradient(to bottom, #f60, #f90);}合并以上代码
以下是整合后的完整代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>嵌入式设备登录</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="login-box">
<img src="background.jpg" class="background">
<h1>设备登录</h1>
<form>
<label for="username">用户名:</label>
<input type="text" id="username" name="username" required>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="登录">
</form>
</div>
</body>
</html>
<style>
body {
background-color: #f2f2f2;
}
.login-box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
background-color: #fff;
padding: 50px;
border-radius: 10px;
box-shadow: 0 0 20px 0 rgba(0,0,0,0.2);
}
.background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
filter: blur(5px);
}
h1 {
margin: 0 0 30px;
padding: 0;
font-size: 28px;
text-align: center;
color: #333;
text-shadow: 2px 2px 2px rgba(0,0,0,0.2);
}
form {
display: flex;
flex-direction: column;
}
label {
margin-bottom: 10px;
font-size: 18px;
color: #333;
text-shadow: 2px 2px 2px rgba(0,0,0,0.2);
}
input[type="text"],
input[type="password"] {
padding: 10px;
border: none;
border-radius: 5px;
background-color: #f2f2f2;
color: #333;
box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
}
input[type="submit"] {
margin-top: 20px;
padding: 10px;
border: none;
border-radius: 5px;
background-color: #f90;
background-image: linear-gradient(to bottom, #f90, #f60);
color: #fff;
font-size: 18px;
cursor: pointer;
box-shadow: 0 2px 2px rgba(0,0,0,0.2);
}
input[type="submit"]:hover {
background-image: linear-gradient(to bottom, #f60, #f90);
}
</style>
```