JavaScript Basics, Login verification

Source: Internet
Author: User

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

A. Put in <body>

B. Put in

C. Put in an external JS file

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Demo</title>    <Script>        functiondisplaydate () {document.getElementById ("Demo"). InnerHTML=Date (); }    </Script>    <Scriptsrc= "Yl.js"></Script></Head><Body>      <P>Hello</P>      <Script>document.write (Date ()) document.getElementById ("Demo"). InnerHTML=Date (); </Script>  <Buttontype= "button"onclick=window.alert ("User name must not start with a number")>Press</Button></Body></HTML>
function myFunction () {Document.getelementbyld ("Demo"). Innerhtml= "My first JavaScript function";}

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 HTML element using InnerHTML.

A. Use the ID property to identify the HTML element.

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

C. Use innerHTML to get or insert element content.

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Demo</title></Head><Body>      <PID= "Demo">Hello</P>      <Script>document.getElementById ("Demo"). InnerHTML=Date (); </Script>  <Buttontype= "button"onclick=window.alert ("User name must not start with a number")>Press</Button></Body></HTML>

3. The login page prepares:

A. Add the error prompt box.

B. Write a good html+css file.

C. Setting the ID of each INPUT element

4. Define JavaScript functions.

A. Verify user name 6-20-bit

B. Verify password 6-20-bit

5.onclick calls this function.

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Login </title>
<link rel= "stylesheet" type= "Text/css" href= "C2.css" >
<script>
function Fnlogin () {
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>
<body>
<div class= "BigBox" >
<div class= "box" >

<div class= "Input_box" >
Account: <input id= "umane" type= "text" placeholder= "Please enter user name" >
</div>
<div class= "Input_box" >
Password: <input id= "UPass" type= "password" placeholder= "Please enter password" >
</div>
<div id= "Error_box" ><br></div>
<div class= "Input_box" >
<button onclick= "Fnlogin ()" > Login </button>
<button Onclick=window.alert ("Do you want to cancel the login?" ") > Cancel </button></div>
</div>
</div>

</body>

Align:center; }.bigbox{Display:-webkit-flex;Display:Flex;width:400px;Height:250px;Padding-left:100px;Padding-top:50px;Background-color:Greenyellow; }#input_box{Align:Center;margin:700px;Padding-left:700px; }#error_box{Color:Black; }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 verification

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.