- Three ways to use <script></script>:
- Put in the <body>
- Put in the
- Placed in an external JS file
- Three ways to output data:
- Use the document.write () method to write content to an HTML document.
- Use the Window.alert () pop-up warning box.
- Writes to an HTML element using InnerHTML.
- Use the ID property to identify the HTML element.
- Use the document.getElementById (ID) method to access HTML elements.
- Use innerHTML to get or insert element content.
- The login page prepares:
- Add an Error prompt box.
- Write a good html+css file.
- Set the ID of each INPUT element
- Defines a JavaScript function.
- Verify user name 6-20-bit
- Verify password 6-20-bit
- The onclick invokes this function.
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Title</title></Head><Body> <P>Hello</P> <Script>document.write (Date ())</Script><Buttontype= "button"onclick=window.alert ("User name cannot start with a number")>Login</Button></Body></HTML>
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Login</title> <Linkrel= "stylesheet"type= "Text/css"href=".. /static/css/1111.css "> <Script> functionMyLogin () {varOuname=document.getElementById ("name") varOerror=document.getElementById ("Error_box") varOpassword=document.getElementById ("Password") if(OUname.value.length<6||OUname.value.length> -) {Oerror.innertext="user name must be 6-20-bit"; return; } Else if(Opassword.value.length<6||Opassword.value.length> -) {Oerror.innertext="Password must be 6-20-bit"; return; } Else{oerror.innerhtml=""; } } </Script></Head><Body><Divclass= "AA" > <Divclass= "Login" ><H2>Login</H2></Div> <Divclass= "Aa1" >Name:<inputID= "Name"type= "text"placeholder= "Please enter user name"><BR>Password:<inputID= "Password"type= "Password"placeholder= "Please enter password"><BR> </Div> <DivID= "Error_box"><BR></Div> <Divclass= "Aa2" > <Buttononclick= "MyLogin ()">Login</Button> <Buttontype= "button"onclick=window.alert ("Whether to cancel login! ")>Cancel</Button> </Div></Body></HTML>
Css:
Div{margin:0 Auto;text-align:Center;Backgroup-color:Gray;}. AA{width:350px;Height:200px;Background-color:Black;Margin-top:100px;}. Login{font-size:25px;Color:Cyan;}. Aa1{font-size:16px;Font-weight:Bold;Color:Cyan; }. Aa2{width:100px;Height:30px;Boder-style:Hidden;}. Design{font-size:10px;Color:Cyan;}#error_box{Color:Cyan;}
JavaScript Basics, Login front-end verification