JavaScript Basics, Login front-end verification

Source: Internet
Author: User
Tags button type

Three ways to use 1.<script></script>:

1. Put in <body>

2. Put in

3. Put in an external JS file

2. Three ways of outputting data:

1. Use the document.write () method to write the contents to an HTML document.

2. Use the Window.alert () pop-up warning box.

3. Write to the HTML element using InnerHTML.

1. Use the id attribute to identify the HTML element.

2. Use the document.getElementById (ID) method to access HTML elements.

3. Use innerHTML to get or insert element content.

<! DOCTYPE html>"en">"  UTF-8">    <title>Demo</title>          document.write (Date ())      </script>  <button type="  button" onclick=window.alert (" username must not start with a number ") > Logim</button></body>

<! DOCTYPE html>"en">"UTF-8"> <title>Demo</title>"Demo">HELLO</p> <script>document.getElementById ("Demo"). InnerHTML =Date (); </script> <button type="Button"Onclick=window.alert ("user name must not start with a number") >LOGIN</button></body>



3. The login page prepares:

1. Add the error notification box.

2. Write the Html+css file.

4. Set the ID of each INPUT element to define the JavaScript function.

1. Verify user name 6-20-bit

2. Verify password 6-20-bit

5.onclick calls this function.

<script>function MyLogin () {var ouname= document.getElementById ("umane"); var oerror= document.getElementById ("Error_box"); var oupass= document.getElementById ("UPass")        if(ouname.value.length<6) {oerror.innerhtml="user name is at least 6 bits"        }        if(ouname.value.length>20) {oerror.innerhtml="user name must not exceed 20 digits"        }        if(ouname.value.length>6&ouname.value.length<20&oupass.value.length<6) {oerror.innerhtml="password is at least 6 bits"        }        if(ouname.value.length>6&ouname.value.length<20&oupass.value.length>20) {oerror.innerhtml="password must not exceed 20 digits"        }    }    </script>class="BigBox"> <divclass="Box"> class="Input_box">Account:<input id="umane"Type="text"Placeholder="Please enter user name"> </div> <divclass="Input_box">Password:<input id="UPass"Type="Password"Placeholder="Please enter your password"> </div> <div id="Error_box"><br></div> <divclass="Input_box"> <button onclick="MyLogin ()"> Login </button> <button onclick=window.alert ("do you want to cancel login? ") > Cancel </button></div> </div> </div></body>
h2{    align:center;   }. bigbox{    -webkit-Flex;    Display:flex;    width:300px;    height:250px;    Padding-left:100px;    Padding-top:50px;    Background-Color:cyan;    } # input_box{    align:center;    margin:500px;    Padding-left:500px;    } # error_box{    color:hotpink;    } body{padding-right:500px; margin-top:100px; padding-left:500px; font-size:16px; padding-bottom:40px; padding-top:40px; Font-family:verdana,arial,helvetica,sans-serif; }

JavaScript Basics, Login front-end verification

Related Article

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.