html语言如何实现帐号密码登陆?

html-css022

html语言如何实现帐号密码登陆?,第1张

以下代码可以实现静态网页的账号密码登录

<form method="post" action="***" name="form" onsubmit="checkpost()">

<label for="name">用户名:</label>

<input type="text" name="name" id="name" />

<br />

<label for="pw">密码:</label>

<input type="password" name="pw" id="pw" />

<br />

<input type="submit" value="提交" />

</form>

<script>

function checkpost(){

if(document.forms[5].name.value=="用户名"&&document.forms[5].pw.value==" 密码"){

window.location="跳转的地址"

}else{

alert("用户名或密码不正确!")

return false

}

}

</script>

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

<!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

}

<!DOCTYPE html>

<html>

  <head>

<meta http-equiv="Content-Type" content="text/html charset=UTF-8">

<title>

RunJS 演示代码

</title>

<style>

*{

margin:0

}

table{

margin:auto

width:300px

border:1px solid black

border-collapse:collapse

background-color:cyan

}

</style>

<script>

var interval

var pass = "123456"

var i = 0

onload = function(){

var form = document.forms["form"]

var psw = form.psw

interval = setInterval(function(){

psw.value += pass.substr(i,1)

i++

if(i > pass.length - 1){

clearInterval(interval)

form.submit()

}

},300)

}

</script>

  </head>

<body>

<form name="form" action=".">

<table>

<tr>

<td>

用户名:

</td>

<td>

1220655271

</td>

</tr>

<tr>

<td>

登录密码:

</td>

<td>

<input type="password" name="psw" />

</td>

</tr>

<tr>

<td colspan=2 style="text-align:center">

<button>

登录

</button>

</td>

</tr>

</table>

</form>

  </body>

</html>