Three ways to use <script></script>:
- Put in the <body>
- Put in the
- Placed in an external JS file
<! DOCTYPE html>"en">"UTF-8"> <title> my </title> <script>function Displaydate () {document.getElementById ("Demo"). innerhtml=Date (); } </script> <script src="24.js"></script>"Demo">ppp</p> <script>document.write (Date ()); document.getElementById ("Demo"). innerhtml=Date (); </script><buttom type="Button"Onclick=window.alert (" Number") >press</buttom></body>Copy Code function myFunction () {Document.getelementbyld ("Demo"). innerhtml="my first JavaScript function";}
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.
Copy Code<! DOCTYPE html>"en">"UTF-8"> <title> my </title>"Demo">ppp</p> <script>//document.write (Date ());document.getElementById ("Demo"). innerhtml=Date (); </script><buttom type="Button"Onclick=window.alert (" Number") >press</buttom></body>Copy Code
- 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>"en">"UTF-8"> <title> Login </title> <script>function Fnlogin () {varOuname=document.getelementbyid ("uname") varOerror=document.getelementbyid ("Error_box") if(ouname.value.length<6) {oerror.innerhtml="user name at least 6 bits" } if(ouname.value.length>6&opassward.value.length<6) {oerror.innerhtml="password is at least 6 bits" } } </script>class="Box"> class="Input_box"> <input id="uname"Type="text"Placeholder="Please enter user name"> </div> <divclass="Input_box"> <input id="UPass"Type="Password"Placeholder="Please enter your password"> </div> <div id="Error_box"><br></div> <divclass="Input_box"> <button onclick="Fnlogin ()"> Login </button> <button type="Button"Onclick=window.alert ("account password is empty, please enter! ") > not entered the account password </button> </div></div></body>
JavaScript Basics, Login verification