Ⅰ 用html代碼編寫一個簡單的登陸界面
<!DOCTYPE html><html lang="zh-CN"><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>登錄</title>
<link href="css/bootstrap.min.css" rel="stylesheet"></head><body><nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="./">jsp作業</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login.html">登錄</a></li>
</ul>
</div>
</div></nav><div class="container">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<form class="form-signin" target="submitFrame" method="post">
<h2 class="form-signin-heading">登錄到jsp作業</h2>
<label for="inputEmail">Email</label>
<input type="email" id="inputEmail" class="form-control" placeholder="請輸入Email" required autofocus><br>
<label for="inputPassword">密碼</label>
<input type="password" id="inputPassword" class="form-control" placeholder="請輸入密碼" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me" checked="checked"> 記住密碼 </label>
</div>
<button type="submit" class="btn btn-primary" id="btn-login">登錄</button>
<a href="reg.html" class="btn btn-default">注冊</a>
</form>
<iframe style="display: none;" name="submitFrame" src="about:blank"></iframe>
</div>
<div class="col-md-4">
</div>
</div>
<script src="js/jquery.min.js"></script></body></html>
Ⅱ 用html javascript做一個用戶注冊窗口,要求實現登錄名不為空,且兩次密碼輸入一致的功能
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button onclick="dengRu()">登入</button>
<button onclick="zhuCe()">注冊</button>
</body>
</html>
<script type="text/javascript">
var a1;var b1;
var a2;var b2;
var a3;var b3;
var ciShu = 1;
function zhuCe(){
alert("歡迎進入注冊界面");
if(ciShu == 1){
a1 = prompt("請注冊您的賬號");
if(a1==""||==null){
alert("賬號不能為空")
}else{
b1 = prompt("請注冊您的密碼");
if(b1==""||b1==null){
alert("密碼不能為空")
}else if(ciShu== 2){
a2 = prompt("請注冊您的賬號");
if(a2==""||a2==null){
alert("賬號不能為空");
}else{
b2 = prompt("請注冊您的密碼");
if(b2==""||b2==null){
alert("密碼不能為空")
}else if(ciShu== 3){
a3 = prompt("請注冊您的賬號");
if(a3==""||a3==null){
alert("賬號不能為空")
}else{
b3 = prompt("請注冊您的密碼");
if(b3==""||b3==null){
alert("密碼不能為空")
}else{
}
console.log("第"+ciShu+"次注冊");
console.log("賬號1為"+a1+",密碼1為"+b1);
console.log("賬號2為"+a2+",密碼2為"+b2);
console.log("賬號3為"+a3+",密碼3為"+b3);
ciShu++;
}
}
}
}
}
}
}
function dengRu(){
alert("歡迎進入登入界面");
var zhangHao = prompt("請輸入您的賬號");
var miMa = prompt("請輸入您的密碼");
if(zhangHao==a1&&miMa==b1||zhangHao==a2&&miMa==b2||zhangHao==a3&&miMa==b3){
alert("登錄成功")
}else{
alert("登錄失敗")
}
}
</script>
Ⅲ 注冊/登陸頁面HTML代碼該怎麼寫
以下為個人原創教學例子,任何人引用需註明出自網路知道用戶am7972,樓主可供參考
該例子涵蓋了文本框、密碼框、下拉菜單、單選框、復選框及文本區的使用
同時在數據的使用方面涵蓋了文本型、數值型、日期型、布爾型的使用
也涵蓋了在會員信息入資料庫前,進行嚴格的數據檢查
不足處,JS驗證還不是太完善,不過有服務端認證足夠了
<title>會員注冊</title>
<script type="text/javascript">
<!--function CheckForm()
{
if(document.userinfo.username.value == "")
{ alert("請輸入姓名,姓名不能為空!");
document.userinfo.username.focus();
return false;
}
if(document.userinfo.username.value.length > 10)
{
alert("輸入的姓名長度最多為10個字元!");
document.userinfo.username.focus();
return false;
}
}
//--></script>
</head>
<body>
<table border="1" width="53%" bordercolorlight="#000000" cellspacing="0" id="table1" height="358" bordercolor="#000000" bordercolordark="#FFFFFF" cellpadding="0">
<form method="POST" action="bb.asp" name="userinfo" onsubmit="return CheckForm();">
<tr><td colspan="2" height="37"> <p align="center">會員注員</td> </tr>
<tr> <td width="37%" align="right">姓名:</td> <td width="61%"> <input type="text" name="username" value="libin" size="13"> </td> </tr>
<tr> <td width="37%" align="right">密碼:</td> <td width="61%"> <input type="password" name="userPassword" size="20" value="123"></td> </tr>
<tr> <td width="37%" align="right">性別:</td> <td width="61%"><input type="radio" value="True" checked name="Sex">男 <input type="radio" name="Sex" value="False">女</td> </tr>
<tr> <td width="37%" align="right">生日:</td> <td width="61%"> <input type="text" name="userSR" size="11" value="1985-03-12"></td> </tr>
<tr> <td width="37%" align="right">年齡:</td> <td width="61%"><input type="text" name="userNL" size="9" value="13"></td> </tr>
<tr> <td width="37%" align="right">愛好:</td> <td width="61%"> <input type="checkbox" name="ah" value="sw">上網 <input type="checkbox" name="ah" value="ds" checked>讀書 <input type="checkbox" name="ah" value="ty">體育</td> </tr>
<tr> <td width="37%" align="right">上網方式:</td> <td width="61%">
<select size="1" name="swfs"> <option selected value="bhsw">撥號上網</option> <option value="wxsw">無線上網</option> <option value="gxsw">光纖上網</option> </select>
</td> </tr>
<tr> <td width="37%" align="right">個人簡介:</td> <td width="61%"><textarea rows="9" name="userGrjs" cols="34"></textarea></td> </tr> <tr> <td colspan="2" height="38"> <p align="center"><input type="submit" value="提交" name="B1"> <input type="reset" value="重置" name="B2"></td>
</tr>
</form>
</table>
====bb.asp的會員注冊非法數據監測====
<%
username = Request("username")
userPassword = Request("userPassword")
Sex = Request("Sex")
userSR = Request("userSR")
userNL = Request("userNL")
ah = Request("ah")
swfs = Request("swfs")
userGrjs = Request("userGrjs")
'判斷數據合法性,絕對不能讓非法數據進入系統
'判斷姓名username合不合法,是否包含非法數據
username = Trim(username) '例如:" 張 三 "經過處理之後變成"張 三"
If username ="" Then
Response.write "姓名不能為空"
Response.End
End If
If Len(username)>10 Then
Response.write "姓名字數不能超過10個字" 'Len("Z")=1 Len("國")=2
Response.End
End If
For i = 1 To Len(username)
q = Mid(username,i,1)
If InStr("!@#$%^&*()_-+|<>?/"",.",q)>0 Then
Response.write "姓名不能包含特殊符號!@#$%^&*()_-+|<>?/"",."
Response.End
End If
Next
'判斷密碼合不合法,是否包含非法數據userPassword = Trim(userPassword)If userPassword ="" Then Response.write "密碼不能為空" Response.EndEnd If
If Len(userPassword)>20 Then
Response.write "密碼字數不能超過20個字"
Response.End
End If
'判斷密碼合不合法,是否包含非法數據
Sex = Trim(Sex)
If Sex = "" Then
Response.write "性別不能為空"
Response.End
End If
If Sex <> "True" And Sex <> "False" Then
Response.write "性別不能為不男不女"
Response.End
End If
'判斷生日合不合法,是否包含非法數據
userSR = Trim(userSR)
If userSR ="" Then
Response.write "生日不能為空"
Response.End
End If
If Len(userSR)<8 Or Len(userSR)>10 Then '例如:2012-6-3 2012-11-23
Response.write "你輸入的生日字數不對,應為2012-6-3或2012-11-23格式"
Response.End
End If
If IsDate(userSR)=False Then
Response.write "你輸入的生日格式不能轉化為日期,請核實"
Response.End
End If
If DateDiff("yyyy",userSR,Date())<1 Or DateDiff("yyyy",userSR,Date())>200 Then
Response.write "根據你輸入的生日你可能小於1歲或已經超過200歲了,請核查重新輸入"
Response.End
End If
'判斷年齡合不合法,是否包含非法數據userNL = Trim(userNL)If userNL ="" Then
Response.write "年齡不能為空"
Response.End
End If
If IsNumeric(userNL)=False Then
Response.write "你輸入的年齡不能轉化為數值,請核查"
Response.End
End If
userNL = CInt(userNL)
If userNL<0 Or userNL>200 Then
Response.write "你輸入的年齡不能小於0歲或者大於200歲,請核查"
Response.End
End If
'判斷愛好合不合法,是否包含非法數據ah = Trim(ah) '選擇多個愛好則系統會用,分開 //測試
ah = Replace(ah," ","")
arrAh = Split(ah,",")
For i = LBound(arrAh) To UBound(arrAh)
If arrAh(i)<>"sw" And arrAh(i)<>"ds" And arrAh(i)<>"ty" Then
Response.write i & "你選擇的愛好有問題,請核查" & arrAh(i)
Response.End
End If
Next
'判斷上網方式合不合法,是否包含非法數據swfs = Trim(swfs)If swfs = "" Then
Response.write "上網方式不能為空"
Response.End
End If
If swfs<>"bhsw" And swfs<>"wxsw" And swfs<>"gxsw" Then
Response.write "你選擇的上網方式有問題,請核查"
Response.End
End If
'判斷個人簡介是否為空,是否超出1000個字
userGrjs = Trim(userGrjs)
If userGrjs = "" Then
Response.write "個人簡介不能為空"
Response.End
End If
If Len(userGrjs) > 1000 Then
Response.write "個人簡介不能超過1000個字"
Response.End
End If
Response.write "數據合法性檢測通過"
%>
====登陸的HTML代碼可相信樓主參照會員注冊代碼應該沒問題了====
Ⅳ 求html登陸界面詳細代碼。要可以登陸,用資料庫保存。
這是我曾經寫過的一個登錄頁面的詳細代碼,供你參考,asp的代碼,不知道你看得懂不?
文件名是:deafaule.asp
<% @ Language=VBScript %>
<!--#include file="inc/jf.asp"-->
<html>
<head>
<title>歡迎使用
<%
Response.Write (JFrs("Company_Name") & " —— " & JFrs("Software_Name"))
Response.Cookies("Visiter")("Identification") = "ChunLeiSky" '設置cookies的標識,在後面檢測瀏覽器是否支持cookies
Response.Cookies("Visiter").Expires = dateadd("n",10,now()) '設置cookies的有效期為10分鍾
Dim an
Randomize
an= int((99999-11111+1) * RND +11111)
session("FrontPage_Yzm")=an
%>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-cn" />
<link rel="stylesheet" type="text/css" href="main.css">
<script language=VBScript src=load.js></script>
<script language="JavaScript">
function FrontPage_valid() {
if (document.FrontPage_Form.loginName.value == "") {
alert("請先輸入 [用戶名] !\n如果沒有帳號請先 注冊!");
document.FrontPage_Form.loginName.focus();
return false;
}
else if (document.FrontPage_Form.loginName.value.length < 2) {
alert("在 [用戶名] 中,請至少輸入 2 個字元!");
document.FrontPage_Form.loginName.focus();
return false;
}
else if (document.FrontPage_Form.loginPassword.value == "") {
alert("請輸入[密碼]!");
document.FrontPage_Form.loginPassword.focus();
return false;
}
else if (document.FrontPage_Form.loginPassword.value.length < 5) {
alert("在 [密碼] 中,請至少輸入 5 個字元!");
document.FrontPage_Form.loginPassword.focus();
return false;
}
else if (document.FrontPage_Form.FrontPage_Yzm.value == "") {
alert("請輸入[驗證碼]!");
document.FrontPage_Form.FrontPage_Yzm.focus();
return false;
}
else if (document.FrontPage_Form.FrontPage_Yzm.value.length != 5) {
alert("在 [驗證碼] 中,請輸入 5 位數字!");
document.FrontPage_Form.FrontPage_Yzm.focus();
return false;
}
else if (document.FrontPage_Form.FrontPage_Yzm.value.length == 5) {
var i=0,ch;
for (i=0;i<5;i++) {
ch=document.FrontPage_Form.FrontPage_Yzm.value.charAt(i);
if (ch<"0" || ch>"9") {
alert("在 [驗證碼] 中,必須輸入 5 位數字!");
document.FrontPage_Form.FrontPage_Yzm.focus();
return false;
break;
}
}
}
else {
return true;
}
}
function setfocus() {
document.FrontPage_Form.loginPassword.focus();
return;
}
</script>
</head>
<script language="JavaScript">
if (screen.width == 1440) {
document.write("<body background='images/bg750.jpg' onload='JavaScript:setfocus();'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />");
}
else if (screen.width == 1280) {
document.write("<body background='images/bg660.jpg' onload='JavaScript:setfocus();'><br /><br /><br /><br /><br /><br /><br /><br />");
}
else {
document.write("<body BGcolor='#5A7EDC' onload='JavaScript:setfocus();'><br /><br /><br /><br /><br /><br /><br />");
}
</script>
<div align="center">
<form method="post" action="login.asp" name="FrontPage_Form" onSubmit="JavaScript:return FrontPage_valid();">
<table border="0" cellpadding="0" cellspacing="0" width="548" height="350" id="table11" background="images/log.jpg">
<tr height="50"><th colspan="4" class="Fir">
<% Response.Write (JFrs("Company_Name") & " —— " & JFrs("Software_Name")) %>
</th></tr>
<tr height="36"><th colspan="4" class="warning">
<%
Dim ErrCode
ErrCode = request.QueryString("ErrCode")
If ErrCode = "-1" Then
Response.Write "<li> 您已成功修改賬號信息,請等待管理員審核!"
ElseIf ErrCode = "0" Then
Response.Write "<li> 您的帳號已成功注冊,請等待管理員審核!"
End If
If ErrCode = "7" Then
Response.Write "<li> [用戶名] 不能為空,且至少2個漢字,最多10個漢字"
End If
If ErrCode = "8" Then
Response.Write "<li> [密碼] 不能為空,且至少5個字元,最多20個字元"
End If
If ErrCode = "9" Then
Response.Write "<li> [驗證碼] 錯誤"
End If
If ErrCode = "10" Then
Response.Write "<li> [用戶名] 未注冊 或 [密碼] 錯誤"
End If
If ErrCode = "20" Then
Response.Write "<li> 您的賬號未通過審核,詳情請咨詢管理員"
End If
ErrCode = ""
%>
</th></tr>
<tr height="37"><th colspan="4" align="left"></th></tr>
<tr height="38">
<td width="202"></td>
<td width="100" align="right">用戶名:</td>
<td width="224"> <input type="text" name="loginName" style="width:160px;height:20px" maxlength="10" title="請輸入用戶名,至少2個漢字,最多10個漢字" value="<% =request.Cookies("Visiter")("VisitName") %>" onFocus="JavaScript:this.select();" onMouseOver="JavaScript:this.focus();" onClick="Javascript:this.value=''"></td>
<td width="22"></td>
</tr>
<tr height="38">
<td width="202"></td>
<td width="100" align="right">密 碼:</td>
<td width="224"> <input type="password" name="loginPassword" style="width:160px;height:20px" maxlength="20" title="請輸入密碼,至少5個字元"></td>
<td width="22"></td>
</tr>
<tr height="38">
<td width="202"></td>
<td width="100" align="right">驗證碼:</td>
<td width="224"> <input name="FrontPage_Yzm" style="width:100px;height:20px" maxlength="5" title="請輸入5位的驗證碼">
<% Response.Write (" " & an) %>
</td>
<td width="22"></td>
</tr>
<tr height="54">
<td width="202"></td>
<th colspan="2" valign="middle">
<input type="image" src="images/login.jpg">
<a href="JavaScript:document.FrontPage_Form.reset();"><img border="0" src="images/reset.jpg"></a>
</th>
<td width="22"></td>
</tr>
<tr height="34">
<td width="202"></td>
<th colspan="2">如果您還沒有帳號,請點此 <a href="reg.asp?ErrCode=0">注冊</a></th>
<td width="22"></td>
</tr>
<tr height="25" class="Sec">
<td width="202" align="center"><% Response.Write (JFrs("Company") & "® 版權所有 ") %>
</td>
<th colspan="3">Copyright&; 2012 All Rights Reserved</th>
</tr>
</table>
</form>
</div>
<script language="JavaScript">
if (screen.width == 1440) {
document.write("<br /><br /><br /><br /><br /><br /><br /><br /><br />");
}
else if (screen.width == 1280){
document.write("<br /><br /><br /><br />");
}
else {
document.write("<br /><br /><br /><br /><br />");
}
</script>
<center>建議使用 IE8.0或更高版本的瀏覽器,推薦解析度1440×900 或更高<br />
<%
Response.Write (JFrs("Company") & "® " & JFrs("Software_Name") & " V1.0")
JFrs.Close
set JFrs = Nothing
CloseDataBase
%>
</center>
</body>
</html>
Ⅳ 求html登陸界面詳細代碼 要可以登陸,用資料庫保存
上面給你的是asp的,這邊給你個php的,你看下,不懂再問我
<?php
include("config.php");
session_start();
/*--------------------刪除cookies記錄,讓cookies過期-----------------------------------*/
if($_GET["del"]=="cookies")
{
setcookie("usercookies", "", time()-3600);
setcookie("pwdcookies", "", time()-3600);
echo "<SCRIPT type=text/javascript>
var n = 5;
var timer = setInterval(function() {
n--;
document.getElementById('second').innerHTML = n;
if (n == 0) {
clearInterval(timer);
window.location = 'login.php';
}
}, 1000);
</SCRIPT>刪除成功<br><B class='chengse STYLE1' id=second>5</B>秒後回到首頁";
exit();
}
/*------------------------如果判斷已經有cookies存在,則進行自動登錄操作----------------------------------*/
if($_COOKIE["usercookies"]!="" and $_COOKIE["pwdcookies"]!="")
{
$username=$_POST["username"];
$userpassword=$_POST["userpassword"];
$sql=mysql_query("select * from user where username='$username' and userpassword='$userpassword'");
$rs=mysql_fetch_array($sql);
echo"自動跳轉成功";
//exit();
}
/*----------------------------點擊登錄按鈕後的動作act=login----------------------------------*/
if($_GET["act"]=="login")
{
/*------------------判斷獲取的驗證碼是否一致-------------------------*/
/*if(strtoupper($_SESSION["vcode"])!=strtoupper($_POST["Code"]))
{
echo("<script type='text/javascript'> alert('對不起,驗證碼錯誤!');location.href='javascript:onclick=history.go(-1)';</script>");
exit();
}*/
/*------------------------點擊登錄按鈕後如果判斷已經有cookies存在,則進行自動登錄操作----------------------------------*/
if($_COOKIE["usercookies"]!="" and $_COOKIE["pwdcookies"]!="")
{
$username=$_POST["username"];
$userpassword=$_POST["userpassword"];
$sql=mysql_query("select * from user where username='$username' and userpassword='$userpassword'");
$rs=mysql_fetch_array($sql);
if($_POST["username"]==$rs["username"] and $_POST["userpassword"]==$rs["userpassword"])
{
echo"<script type='text/javascript'> alert('存在cookies登錄跳轉成功!');location.href='javascript:onclick=history.go(-1)';</script>";
exit();
}
else
{
echo"<script type='text/javascript'> alert('存在cookies登錄跳轉失敗!');location.href='javascript:onclick=history.go(-1)';</script>";
exit();
}
exit();
}
/*-------------------點擊登錄後判斷cookies不存在則進行登錄比較用戶名密碼------------------------------*/
$username=$_POST["username"];
$userpassword=md5($_POST["userpassword"]);
$sql=mysql_query("select * from user where username='$username' and userpassword='$userpassword'");
if($rs=mysql_fetch_array($sql))
{
/*---------------------用戶名密碼判斷正確,寫入cookies動作,同時進行跳轉------------------------------------*/
setcookie("usercookies", $_POST["username"], time()+3600*48);
setcookie("pwdcookies", md5($_POST["userpassword"]), time()+3600*24);
header('Location: http://www..com/');
exit();
}
else
{
/*-------------------判斷用戶名密碼錯誤,彈出錯誤提示---------------------------*/
echo "<script type='text/javascript'> alert('用戶名或密碼錯誤,請重新輸入!');location.href='javascript:onclick=history.go(-1)';</script>";
exit();
}
}
/*
$user_IP = $_SERVER["REMOTE_ADDR"];//獲取訪問者IP
$file_name=date('Y-m-d').'.txt';//以當前的日期建立txt文件
$file=fopen($file_name,"a+");//如果存在該文件就打開,如果不存在就創建
fwrite($file,$user_IP.'--'.date('Y-m-d H:i:s')."\r\n");//將訪問者IP及當前時刻寫到文件最後,\r\n在文檔最後換行
fclose($file);//關閉文件
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>COOKIES判斷是否自動登錄</title>
</head>
<body>
<form action="?act=login" method="post">
<input name="username" type="text" id="username" value="<?php if($_COOKIE["usercookies"]!=""){echo $_COOKIE["usercookies"];}?>" />
<input name="userpassword" type="password" id="userpassword" value="<?php if($_COOKIE["pwdcookies"]!=""){echo $_COOKIE["pwdcookies"];}?>"/>
<!--<img src="yanzhengma_class.php" title="看不清楚?請點擊刷新驗證碼" onClick="this.src='yanzhengma_class.php?t='+(new Date().getTime());" height="20px;"><input name="Code" type="text" id="Code" value="" />-->
<input name="" type="submit" />
</form>
<a href="?del=cookies">刪除cookies</a>
</body>
</html>
Ⅵ 注冊/登陸頁面HTML代碼該怎麼寫
以下為個人原創教學例子,任何人引用需註明出自網路知道用戶am7972,樓主可供參考x0dx0a該例子涵蓋了文本框、密碼框、下拉菜單、單選框、復選框及文本區的使用x0dx0a同時在數據的使用方面涵蓋了文本型、數值型、日期型、布爾型的使用x0dx0a也涵蓋了在會員信息入資料庫前,進行嚴格的數據檢查x0dx0a不足處,JS驗證還不是太完善,不過有服務端認證足夠了x0dx0a
Ⅶ 注冊頁面html中的登錄按鈕代碼
<input type="button" name="submit" value="Log in" class="left" onclick="OnSubmits()" />
Ⅷ javascript html 設計一個登錄界面
注冊頁面代碼:
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>注冊</title>
</head>
<body>
<formmethod="post"onsubmit="returnfalse"id="form">
<inputtype="text"name="username"placeholder="用戶名"><br>
<inputtype="password"name="password"placeholder="密碼"><br>
<inputtype="password"name="rePassword"placeholder="再次輸入密碼"><br>
<inputtype="submit"onclick="register_user()"value="注冊"><br>
</form>
<ahref="login.html">去登錄</a><script>
varlocalDB=openDatabase('localDB','1.0','TestDB',2*1024*1024);
localDB.transaction(function(ts){
ts.executeSql('CREATETABLEIFNOTEXISTSuser(username,password)')
});
functionregister_user(){
varusername=document.getElementsByTagName("input")[0].value;
varpassword=document.getElementsByTagName("input")[1].value;
varrePassword=document.getElementsByTagName("input")[2].value;
if(password!=rePassword)
{
alert("兩次輸入的密碼不同,請重新輸入");
}else
{
localDB.transaction(function(ts){
ts.executeSql("INSERTINTOuser(username,password)VALUES('"+username+"','"+password+"');");
alert("注冊成功");
});
}
}
</script>
</body>
</html>
登錄頁面代碼:
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>登錄</title>
</head>
<body>
<formonsubmit="returnfalse"method="post">
<inputtype="text"placeholder="用戶名"><br>
<inputtype="password"placeholder="密碼"><br>
<inputtype="submit"value="登錄"onclick="login()"><br>
</form>
<ahref="register.html">去注冊</a>
<script>
varlocalDB=openDatabase('localDB','1.0','TestDB',2*1024*1024);
localDB.transaction(function(ts){
ts.executeSql("SELECT*FROMuser",[],function(tx,results){
varlen=results.rows.length;
if(len<=0)
{
localDB.transaction(function(ts){
ts.executeSql('CREATETABLEIFNOTEXISTSuser(username,password)')
});
}
});
});
functionlogin(){
varusername=document.getElementsByTagName("input")[0].value;
varpassword=document.getElementsByTagName("input")[1].value;
localDB.transaction(function(ts){
ts.executeSql("SELECT*FROMuserWHEREusername='"+username+"';",[],function(ts,res){
if(res.rows.length<=0)
{
alert("登錄失敗,用戶未注冊");
}elseif(password==res.rows[0].password)
{
alert("登錄成功,三秒後跳轉到網路");
setInterval(function(){
location.href="https://www..com";
},3000);
}else
{
alert("登錄失敗,密碼錯誤");
}
});
})
}
</script>
</body>
</html>
以上代碼使用了WEB SQL,還請選擇合適的瀏覽器查看。