<html>
<body>
<script>
function check()
{
if (p1.value==p2.value){alert('密码相等');}
else alert('密码不等');
}
</script>
<input type=password name=p1><br>
<input type=password name=p2><br>
<input type=button value=检验 onclick=check()>
</body>
</html>

解决方案 »

  1.   

    <INPUT id=password1 name=password1 type=password><INPUT id=button1 name=button1 type=button value=Button onclick="if (password1.value==password2.value)alert('密码一样')"><INPUT 
    id=password2 name=password2 type=password>
      

  2.   

    function repassword(theForm)
     {

     if(theForm.inputUserPassword.value==theForm.repassword.value)
     {

     return (true);
     }
     else
     {
       alert("两次密码不一致,请重新输入");
       theForm.inputUserPassword.value="";
       theForm.repassword.value="";
       return (false);
       }
       }
    <form name="form1" method="post" action="insert.php" onSubmit="return repassword(form1)">
    为什么不执行我得javascript
      

  3.   

    document.theForm.inputUserPassword.value==document.theForm.repassword.value
      

  4.   

    响应一个事件,如button的onclick事件,或者响应submit事件,另:你的代码不完整,怎么知道你出错在哪里了?
    js代码要在<script>和</script>之中!
      

  5.   

    http://expert.csdn.net/Expert/topic/2289/2289198.xml?temp=.1907007
      

  6.   

    <HTML>
    <HEAD>
    <title>test</title>
    <script language="javaScript">
    function issapce()
    {
         if (document.book.password.value=="") 
         {
             alert ("请输入您的密码 !")
             document.book.password.focus();
             return false
         }
            
         if (document.book.password.value.length<4) 
         {
             alert ("您的密码太短了!")
             document.book.password.focus();
             document.book.password.value="";
             document.book.repassword.value="";
             return false
         }
            
         if (document.book.repassword.value=="") 
         {
              alert ("请输入您的重复密码!")
              document.book.repassword.focus();       
              return false
         }
        
      if (document.book.password.value!=document.book.repassword.value) 
      {
         alert ("两次密码不一致 !");
         document.book.password.focus();
         document.book.password.value="";
         document.book.repassword.value="";
         return false;
      }
      return true;
    }
     
      function validIfo()
    {
      if(!issapce()) return false;
    }
    </script>
    </HEAD> 
    <BODY>
    <form action="" name="book" onSubmit="return validIfo()" method="post">
    <table width="90%" cellspacing="2" border="0" align="center" cellpadding="3">
        <tr> 
             <td width="128"><font color="#FF0000">*</font>密码:</td>
             <td width="262"> 
                 <input type="password"  size=30 name="password">
             </td>
             <td width="268">→ 密码至少4位,区分大小写。</td>
         </tr>
         <tr> 
             <td width="128"><font color="#FF0000">*</font>重复密码:</td>
             <td colspan="2"> 
               <input type="password" size=30 name="repassword">
             </td>
         </tr>
     <tr><td>
      <input type="submit" value="下一步&gt;&gt;" name="submit">
      </td><td></td></tr>
    </table>
    </form>
    </BODY>
    </HTML>
      

  7.   

    试试:<input type="submit" value="下一步" name="submit" onclick="return issapce();">