求大神帮帮我js验证两次输入密码是否一致总是提交验证不了 下面是我贴出的代码
<s:formaction="passwordEdit"id="myform"theme="simple"onfocus="returnconfirmPassword()...
<s:form action="passwordEdit" id="myform" theme="simple" onfocus="return confirmPassword();">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td>新密码</td>
<td><s:password id="userPassword" name="user.password"/></td>
</tr>
<tr>
<td>确认密码</td>
<td><input type="password" id="confirmPassword" name="confirmPassword" /></td>
</tr>
<tr>
<td><s:hidden name="user.userId"></s:hidden></td>
<td>
<s:submit value="保存" />
<input type="button" value="取消" onclick="window.location.href='UserList'"/>
</td>
</tr>
</table>
</s:form>
<script type="text/javascript">
function confirmPassword(){
var pwd1=document.getElementById("userPassword").value;
var pwd2=document.getElementById("confirmPassword").value;
if(pwd1!=pwd2){
alert("两次输入不一致");
return false;
}
}
</script> 展开
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td>新密码</td>
<td><s:password id="userPassword" name="user.password"/></td>
</tr>
<tr>
<td>确认密码</td>
<td><input type="password" id="confirmPassword" name="confirmPassword" /></td>
</tr>
<tr>
<td><s:hidden name="user.userId"></s:hidden></td>
<td>
<s:submit value="保存" />
<input type="button" value="取消" onclick="window.location.href='UserList'"/>
</td>
</tr>
</table>
</s:form>
<script type="text/javascript">
function confirmPassword(){
var pwd1=document.getElementById("userPassword").value;
var pwd2=document.getElementById("confirmPassword").value;
if(pwd1!=pwd2){
alert("两次输入不一致");
return false;
}
}
</script> 展开
1个回答
展开全部
不是点击事件么?怎么是onfocus。
还有是不是需要在confirmPassword中最后返回一个true?
还有是不是需要在confirmPassword中最后返回一个true?
更多追问追答
追问
您能帮我贴上修改过的代码吗? 谢谢您
追答
写了一个简单的,你看一下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="a.php" method="get">
<input type="text" value="5" name="user">
<input type="password" id="userPassword" name="pwd">
<input type="password" id="confirmPassword">
<input type="submit" id="btn" value="验证">
</form>
<script type="text/javascript">
var form1 = document.getElementById('btn');
form1.onclick = function(){
var pwd2 = document.getElementById("confirmPassword").value;
var pwd1=document.getElementById("userPassword").value;
if(pwd1!=pwd2){
alert("两次输入不一致");
return false;
}
}
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询