Example code for js to implement the simple login function

Source: Internet
Author: User

Copy codeThe Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Title> Login.html </title>

<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "description" content = "this is my page">
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8">

<! -- <Link rel = "stylesheet" type = "text/css" href = "./styles.css"> -->
<Script type = "text/javascript">
Function checkuser (){
If ($ ('uname' = "lala") & $ ('pwd') = "123 "){
Return true;
} Else {
Return false;
}
}

Function $ (id ){
Return document. getElementById (id). value;
}
</Script>
</Head>

<Body>
<Form action = "OK .html">
U: <input type = "text" id = "uname"/> <br>
P: <input type = "password" id = "pwd"/> <br>
<Input type = "submit" value = "login" onclick = "return checkuser ()"/>
</Form>
</Body>
</Html>


This is the logon page. The logon is successful only when the user name is lala and the password is 123. Use return in The onclick event to prevent page Jump when the user name and password do not match. The logon success page contains the waiting seconds. The Code is as follows:
Copy codeThe Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Title> OK .html </title>

<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "description" content = "this is my page">
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8">

<! -- <Link rel = "stylesheet" type = "text/css" href = "./styles.css"> -->
<Script type = "text/javascript">
Function tiao (){
ClearInterval (mytime );
Window. open ("manage.html", "_ self ");
}

SetTimeout ("tiao ()", 5000 );

Function changeSec (){
// Obtain the myspan value.
$ ('Myspan '). innerText = $ ('myspan'). innerText-1;
}

Function $ (id ){
Return document. getElementById (id );
}
Var mytime = setInterval ("changeSec ()", 1000 );
</Script>
</Head>

<Body>
Log on successfully. <span id = "myspan"> 5 </span> seconds later, the page is automatically displayed.
</Body>
</Html>


The key lies in the use of several functions. setTimeout ("tiao ()", 5000); the function is to open the page and wait for 5 seconds to call the tiao () function. SetInterval ("changeSec ()", 1000); the function calls the changeSec () function once every one second. This completes the simple login function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.