日期:2014-05-16  浏览次数:20306 次

用javaScript验证密码输入是否一致,当判断出不一致时,怎么才能重填表单呢?
源代码如下:
<%@page   contentType= "text/html;   charset=GBK "%>
<html>
<head>
<title> register </title>

</head>
<body   bgcolor= "#ffffff ">

<form   name= "thisForm "   action= "insert.jsp "   method= "GET "   onsubmit= "return   formCheck() ">
<script   language= "JavaScript "   type= "text/JavaScript ">
function   formCheck(){
        if(thisForm.password.value!=thisForm.pass.value){
        alert( "两次输入的密码不一致,请再次输入! ");
       
       
    }
} </script>
<p   align= "center ">
<table>

    <tr>
        <td   align= "right "> 密码: </td>
        <td>
            <input   type= "password "   name= "password "/>
        </td>
    </tr>
    <tr>
        <td   align= "right "> 请再次输入密码: </td>
        <td>
            <input   type= "password "   name= "pass "/>
        </td>
    </tr>
    <tr>
    <td> <input   type= "submit "   name= "sub "   value= "提交 "> </td>
    <td> <input   type= "reset "   name= "res "   value= "重写 ">
    </tr>


</table>
</form>
</body>
</html>

问题是:
当判断出两次输入的密码不一致时,弹出一个对话框后,选择重填表单时,就直接跳转到沁insert.jsp文件去了,怎样才能实现再次填表单的功能呢?求教!


------解决方案--------------------
<head>
<title> register </title>

</head>
<body bgcolor= "#ffffff ">

<form name= "thisForm " action= "# " method= "GET " onsubmit= "return formCheck() ">
<script language= "JavaScript " type= "text/JavaScript ">
function formCheck(){
if(thisForm.password.value!=thisForm.pass.value){
alert( "两次输入的密码不一致,请再次输入! ");
return false;


}
return true;
} </script>
<p align= "center ">
<table>

<tr>
<td align= "right "> 密码: </td>
<td>
<input type= "password " name= "password "/>
</td>
</tr>
<tr>
<td align= "right "> 请再次输入密码: </td>
<td>
<input type= "password " name= "pass "/>
</td>
</tr>
<tr>
<td> <input type= "submit " name= "sub " value= "提交 "> </td>
<td> <input type= "reset " name= "res " value= "重写 ">