- 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.
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Javascript</title></Head><Body> <PID= "Demo">Abcccc</P> <Script>document.write (Date ()). InnerHTML=aaaaaaaaa; document.getElementById ("Demo"). InnerHTML= 123456789; </Script> <Buttontype= "button"onclick=window.alert ("number")>Press</Button></Body></HTML>
- 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>Login</title> <Linkrel= "stylesheet"href= "Style.css"type= "Text/css"> <Script> functionFnlogin () {varOuname=document.getElementById ("uname") varOerror=document.getElementById ("Error_box") varOuword=document.getElementById ("Uword") if(OUname.value.length<6) {oerror.innerhtml= "user name at least 4 bits" } if(OUname.value.length==0) {oerror.innerhtml= "Please enter user name" } if(OUname.value.length> A) {oerror.innerhtml= "user name up to 13 bits" } if(OUword.value.length==0) {oerror.innerhtml= "Please enter your password" } if(OUword.value.length<6) {oerror.innerhtml= "Password at least 6 digits" } if(OUword.value.length> -) {oerror.innerhtml= "password up to 20 bits" } } </Script></Head><Bodystyle= "Background-color:aliceblue"> <Divclass= "box" > <H2class= "Denglu">Login</H2> <Divclass= "Input_box"> <inputID= "Uname"type= "text"placeholder= "Please enter user name"> </Div> <Divclass= "Input_box"> <inputID= "Uword"type= "Password"placeholder= "Please enter password"> </Div> <DivID= "Error_box"><BR></Div> <Divclass= "Input_box"> <Buttononclick= "Fnlogin ()">Login</Button> </Div> </Div></Body></HTML>
. Box{ border: 1px solid #cccccc; Width: 334px; margin: 5px; text-align: center; } . Denglu{ background-color: cornflowerblue; font-family: Chinese in italics ; font-size: 35px; } . Input_box{ height: 40px; }
Job 17--javascript Basics, login verification