登录:
<!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>
<link rel="stylesheet" href="login.css">
</head>
<body>
<div class="login">
<h1>登录</h1>
<ul>
<li class="user-text">账号:<input type="username" class="input-text" ></li>
<li class="user-text">密码:<input type="password" class="input-text"></li>
<li class="unpassword">忘记密码</li>
<li><button class="btn" onclick="submit()">登录</button></li>
</ul>
</div>
<script>
var arr = document.getElementsByClassName('input-text');
function submit(){
var username = arr[0].value;
var password = arr[1].value;
console.log(username,password)
if(username == ''&& password == ''){
alert('账号密码不能为空!')
}else if(username =='chenyirong'&&password=='123456'){
window.location='./Forms.html'
}else{
alert('账号密码错误!')
}
}
</script>
</body>
</html>
登录css:
*{
padding: 0;
margin: 0;
}
body{
background-image: url(./1.jpg);
background-size: cover;
}
.login {
width: 400px;
height: 450px;
/* border: 1px solid rgb(0, 0, 0); */
margin: auto auto;
border-radius: 25px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -225px;
margin-left: -200px;
background-color: rgb(255, 255, 255);
box-shadow: 2px 2px 3px #fcf2e1;
}
.login li {
list-style-type:none;
}
.login h1 {
text-align: center;
/* border: 1px solid red; */
line-height: 100px;
font-size: 35px;
position: relative;
top: 10px;
}
.user-text {
position: relative;
top: 10px;
width: 300px;
height: 80px;
margin: 0px auto;
border-radius: 10px;
/* border: 1px solid red; */
font-size: 20px;
}
.login .user-text .input-text:hover {
border-radius: 12px;
cursor:pointer;
}
.input-text {
/* border: 2px solid red; */
width: 190px;
height: 20px;
border-radius: 10px;
font-size: 20px;
border: 2px solid rgb(163, 163, 163);
padding: 20px 20px;
margin: 7px auto;
}
.unpassword {
/* border: 1px solid red; */
position: relative;
left:285px;
top: 27px;
display: initial;
}
.unpassword:hover {
cursor:pointer;
color: #484847;
font-weight: 600;
}
.btn {
height: 55px;
border-radius: 15px;
border: none;
display: block;
width: 300px;
margin: 50px auto;
padding: 10px 20px;
color: white;
font-size: 20px;
text-align: center;
background-image: linear-gradient(to bottom right, rgb(0, 225, 255) ,rgb(89, 0, 255), rgb(195, 0, 255));
}
.btn:hover {
cursor:pointer;
background-image: linear-gradient(to bottom right,rgb(195, 0, 255),rgb(89, 0, 255), rgb(0, 225, 255) );
}
表单:
<!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>
<link rel="stylesheet" href="Forms.css">
</head>
<body>
<div class="box">
<h1>人员登记系统</h1>
<div class="people-list">
<ul>
<li>姓名:<input type="text" class="input-text"></li>
<li>性别:
<input type="radio" value="男" name="sex" class="radio">
<label for="sex1">男</label>
<input type="radio" value="女" name="sex" class="radio">
<label for="sex2">女</label>
</li>
<li>地址:
<select name="city" id="city">
<option>北京</option>
<option>上海</option>
<option>天津</option>
<option>深圳</option>
</select>
</li>
<li>爱好:
<input type="checkbox" class="checkbox" value="听音乐"><label>听音乐</label>
<input type="checkbox" class="checkbox" value="看小说"><label>看小说</label>
<input type="checkbox" class="checkbox" value="追剧"><label>追剧</label>
</li>
<li class="remarks">
<span> 备注:</span>
<textarea name="" id="" cols="30" rows="10" class="textarea"></textarea>
</li>
<li >
<button class="btn" onclick="submit()">提交</button>
</li>
</ul>
</div>
<script>
var username = document.getElementsByClassName('input-text');
var sex = document.getElementsByClassName('radio');
var select = document.getElementsByTagName('select')[0];
var check = document.getElementsByClassName('checkbox');
var textarea = document.getElementsByClassName('textarea')[0];
function submit() {
var sexcheck = '男';
for (let i = 0; i < sex.length; i++) {
if (sex[i].checked) {
sexcheck = sex[i].value
}
}
let checkarr = []
for (let i = 0; i < check.length; i++) {
if (check[i].checked) {
checkarr.push(check[i].value)
}
}
var obj = {
username: username[0].value,
sex: sexcheck,
address: select.value,
bobby: checkarr,
textarea: textarea.value
}
console.log(obj)
var result = false;
for (let key in obj) {
if (!obj[key]) {
alert('信息未填写完整,不能提交')
return
} else {
result = true
}
}
if (result) {
alert('提交成功')
}
}
</script>
</div>
</body>
</html>
表单css:
*{
padding: 0;
margin: 0;
}
body{
background-image: url(./1.jpg);
background-size: cover;
}
.box {
width: 400px;
height: 600px;
/* border: 1px solid rgb(0, 0, 0); */
margin: auto auto;
border-radius: 25px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -290px;
margin-left: -200px;
background-color: rgb(255, 255, 255);
box-shadow: 2px 2px 3px #fcf2e1;
}
li {
list-style-type:none;
}
.box h1 {
text-align: center;
margin: 30px auto;
}
.people-list {
width: 81%;
/* border: 1px solid red; */
margin: 0px auto;
}
.people-list li {
margin: 20px auto;
font-size: 20px;
}
select {
font-size: 20px;
color: rgb(87, 87, 87);
border: 2px solid rgb(95, 95, 95);
}
select:hover {
cursor: pointer;
color: rgb(0, 0, 0);
}
.input-text {
font-size: 20px;
border: 2px solid rgb(95, 95, 95);
}
.input-text:hover {
cursor: pointer;
}
.radio {
font-size: 20px;
}
.radio:hover {
cursor:pointer;
}
.remarks {
display: flex;
}
textarea {
width: 250px;
letter-spacing:2px;
}
.remarks textarea {
font-size: 18px;
line-height: 30px;
border-radius: 3px;
height: 200px;
border: 2px solid rgb(95, 95, 95);
}
.remarks textarea:hover {
cursor:pointer;
}
.checkbox:hover {
cursor:pointer;
}
input[type="checkbox"] {
width: 15px;
height: 15px;
display: inline-block;
text-align: center;
}
label {
position: relative;
left: 3px;
}
.btn {
position: relative;
top: 8px;
border-radius: 15px;
border: none;
display: block;
width: 250px;
margin: 20px auto;
padding: 10px 20px;
color: white;
font-size: 20px;
text-align: center;
background-image: linear-gradient(to bottom right, rgb(0, 225, 255) ,rgb(89, 0, 255), rgb(195, 0, 255));
}
.btn:hover {
cursor:pointer;
background-image: linear-gradient(to bottom right,rgb(195, 0, 255),rgb(89, 0, 255), rgb(0, 225, 255) );
}