html登录页面怎么做

html-css07

html登录页面怎么做,第1张

这是上课时老师演示的代码,只是前端的代码

<!DOCTYPE html>

<html>

<head>

<title>login.html</title>

<title>登录</title>

<link rel="stylesheet" type="text/css" href="./CSS/login.css">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="this is my page">

<meta http-equiv="content-type" content="text/htmlcharset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

</head>

<body>

<div id="container">

<h1 id="title">小菊花爱心书店</h1>

<div id="information">

<form action="first.html">

<div id="box">

账号:<input type="text" name="keyName">

<br>

密码:<input type="password" name="userPass">

<br>

<input id="B" class="button1" type="submit" name="buyer" value="login">

<br>

<a href="register.html">立即注册</a>

</div>

</form>

</div>

</div>

</body>

</html>

------------------------------------------------

css文件

------------------------------------------------

@CHARSET "GB2312"

body{

background-image:url(../img/login.jpg)

background-size: cover

margin: 0

padding: 0

}

#container{

height:500px

width:400px

background-color:#D2B571

border-radius: 10px

margin: 100px auto

position:relative

box-shadow:2px 2px 10px #888888

}

h1{

text-align: center

padding-top:50px

color: white

}

#information{

background-color: #F5F4F2

height: 350px

width:400px

position:absolute

margin-top: 10px

}

#box{

width:200px

margin-left: 100px

margin-top: 60px

}

input{

display: block

width: 200px

padding-top:5px

height:35px

border: 1.5px solid #eee

border-radius:10px

background-color:#F4F8FF

}

.button1 {

height:35px

margin-top: 20px

padding: 5px 15px

text-align: center

background-color: #F48951

color: white

border: 0px

border-radius:10px

box-shadow:2px 2px 10px #888888

}

.button1:hover {

background-color: white

color: #F48951

border: 1.5px solid #F48951

}

button{

width:90px

position:absolute

top:70px

}

button:hover {

width:90px

position:absolute

top:62px

}

HTML页面用 script 验证不是必须要用 form 的,可以直接给页面里的 DOM 对象定义 id 属性,用 javascript 操作 DOM 对象即可。

针对您提的问题想要实现的效果,下面说说不用 form 表单和数据库来实现用户名和密码验证的方法:

1、首先,给 HTML 页面里的用户名和密码输入框都定义一个id属性,例如:

用户名:

密   码:

2、其次,放置一个按钮登录

3、编写 javascript 脚本代码,主要思路如下:

(1)为按钮增加一个 click 的监听,当鼠标点击该按钮时执行;

(2)获取 input 用户名和密码输入框的输入值;

(3)验证输入值是否符合要求;

(4)符合要求页面跳转到设置的指定页面;

(5)不符合要求提示用户输入错误。

4、最后,在浏览器里运行该页面,测试一下效果。完整代码如下图所示。