point 1:js in the comparison string is equal, JS in the "= =" to determine whether the equality , this is not the same as in Java, Java is. Equals () This method.
In the previously written Ajax demo, because of the use of. Equals () to compare two passwords are equal, for a long time did not find the reason. So remember that js is "= =" instead of the. Equals () method.
Instance:
<script type= "Text/javascript" >function Checkpassword () {var pass1 = document.getElementById ("Passwod"). Value; var pass2 = document.getElementById ("Confirm"). Value;alert ("Pass1:" +pass1+ ", Pass2:" +pass2 "); PASS1==PASS2)) {//can be compared normally, //used before! Pass1.equals (PASS2)), depressed for a long time only to find that this is not the same as in Java alert ("Jinlai");d Ocument.getelementbyid ("Confirm"). Innerhtml= "Password inconsistent, Please confirm and re-enter the ";d Ocument.getelementbyid (" name "). focus ();//relocate to the Account entry Section}}</script>
The corresponding HTML code is as follows:
<body>name:<input type= "text" id= "name" Name= "UserName" onblur= "CheckName ()"/><span id= "Span1" class= "S1" ></span></br>password:<input type= "password" name= "password" id= "password"/></br> Confirm: <input type= "password" id= "confirm" onblur= "Checkpassword ()"/><span id= "span2" class= "S1" ></ Span></body>
JS Summary Summary (later all collected in this article)