Html code:
Copy to ClipboardReference: [www.bkjia.com] <! Doctype html public "-// W3C // dtd html 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Untitled Document </title>
</Head>
<Body>
<Form name = "frm1" method = "post" onsubmit = "loginCheck ()">
<P> UserName: <input type = "text" name = "username"/> </p>
<P> Password: <input type = "password" name = "password"/> </p>
<P>
<Input type = "submit" value = "Login"/>
<Input type = "reset" value = "Reset"/>
</P>
</Form>
</Body>
</Html>
Js Code:
Copy to ClipboardReference: [www.bkjia.com] <script language = "JavaScript" type = "text/javascript">
Function setCookie (name, value, expires, path, domain, secure ){
Var curcookie = name + "=" + encodeURI (value)
+ (Expires )? "; Expires =" + expires. toGMTString ():"")
+ (Path )? "; Path =" + path :"")
+ (Domain )? "; Domain =" + domain :"")
+ (Secure )? "; Secure ":"");
Document. cookie = curcookie;
}
Function getCookie (name ){
If (document. cookie. length> 0 ){
Start = document. cookie. indexOf (name + "= ");
If (start! =-1 ){
Start = start + name. length + 1;
End = document. cookie. indexOf (";", start );
If (end =-1 ){
End = document. cookie. length;
}
}
Return decodeURI (document. cookie. substring (start, end ));
}
Return "";
}
Function loginCheck (){
Var name = document. frm1.username. value;
Var pass = document. frm1.password. value;
If (name = "zghlx" & pass = "123 "){
Var login = true;
Var now = new Date ();
Now. setDate (now. getDate () + 30 );
SetCookie ("login", login, now );
Window. location. href = "index.html ";
}
}
Function userlogin (){
Var login = getCookie ("login ");
If (login! = Null & login! = ""){
Alert ("Welcome ...");
Window. location. href = "index.html ";
}
}
Userlogin ();
</Script>
Source: http://www.cnblogs.com/zghlx/