Improving the reuse of methods by using the method of transmitting parameters
Here's a string concatenation operation involving JavaScript
</tr> <<tr height= "40px" > <td>User name</td> <td> <font color= "Red" >*<inpu T type= "text" name= "user" size= "32px" id= "user"onfocus= "Showtips" (' User ', ' username must be filled! ' Onblur= ' checkuser (' user ', ' username cannot be null ') "/> <span id=" Userspan "></SPAN>&L T;/font> </td> </tr> & Lt;tr height= "40px" > <td>Password</td> <td> <font color= "Red" >*<inpu T type= "password" name= "password" id= "password" size= "32px"onfocus= "Showtips" (' Password ', ' password must be filled! ' Onblur= ' checkuser (' password ', ' Password cannot be empty ') '/> <span id= ' Passwordspan ' >< /span></font> </td> </tr>
<script>functionshowtips (id,info) {document.getElementById (id+ "span"). innerhtml= "<font color= ' Gray ' >" +info+ "</font>" } functionCheckUser (id,info) {//1. Get user-entered user name data varUvalue=document.getElementById (ID). value; //2. Perform the validation if(uvalue== "") {document.getElementById (id+ "span"). innerhtml= "<font color= ' Gray ' >" +info+ "</font>" }Else{document.getElementById (id+ "span"). Innerhtml= "" } } </script>
JavaScript gets focus and loses focus event