怎么用javascript判断2次密码不一致。。弹窗求具体代码
<formaction="<?phpecho$editFormAction;?>""method="post"name="form2"id="form2"onsubmit...
<form action="<?php echo $editFormAction; ?>" "method="post" name="form2" id="form2" onsubmit="MM_validateForm('username','','R','upassword','','R');return document.MM_returnValue">
<table width="614" align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">用户名:</td>
<td><input name="username" type="text" id="username" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">密码:</td>
<td><input name="upassword" type="password" id="upassword" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">重复密码:</td>
<td><input name="repassword" type="password" id="repassword" value="" size="32" /></td> 展开
<table width="614" align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">用户名:</td>
<td><input name="username" type="text" id="username" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">密码:</td>
<td><input name="upassword" type="password" id="upassword" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">重复密码:</td>
<td><input name="repassword" type="password" id="repassword" value="" size="32" /></td> 展开
2个回答
展开全部
var pwd = document.getElementById("upassword").value;
var repwd = document.getElementById("repassword").value;
if (pwd == "") { 这是为空的
} else if (repwd == "") { 重复密码为空的
} else if (pwd != repwd) { 两次输入不相同
}
这里最好用正则表达式或者其他什么方法为javascript加一个trim()方法,把两边空格去掉
用jquery也可以实现
var repwd = document.getElementById("repassword").value;
if (pwd == "") { 这是为空的
} else if (repwd == "") { 重复密码为空的
} else if (pwd != repwd) { 两次输入不相同
}
这里最好用正则表达式或者其他什么方法为javascript加一个trim()方法,把两边空格去掉
用jquery也可以实现
展开全部
<script>
function on_submit(){
var username=document.getElementById("username");
var pwd=document.getElementById("upassword");
var repwd=document.getElementById("repassword");
if(pwd.value!=repwd.value){
alert("两次密码不一致");
pwd.value="";
repwd.value="";
pwd.focus();
return false;
}
}
</script>
</head>
<body>
<form action="" method="post" name="form2" id="form2" onsubmit="return on_submit()">
<table width="614" align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">用户名:</td>
<td><input name="username" type="text" id="username" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">密码:</td>
<td><input name="upassword" type="password" id="upassword" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">重复密码:</td>
<td><input name="repassword" type="password" id="repassword" value="" size="32" /></td>
</tr>
<tr><td></td><td><input type="submit" value="确定" /></td></tr>
</table>
</form>
</body>
function on_submit(){
var username=document.getElementById("username");
var pwd=document.getElementById("upassword");
var repwd=document.getElementById("repassword");
if(pwd.value!=repwd.value){
alert("两次密码不一致");
pwd.value="";
repwd.value="";
pwd.focus();
return false;
}
}
</script>
</head>
<body>
<form action="" method="post" name="form2" id="form2" onsubmit="return on_submit()">
<table width="614" align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">用户名:</td>
<td><input name="username" type="text" id="username" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">密码:</td>
<td><input name="upassword" type="password" id="upassword" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">重复密码:</td>
<td><input name="repassword" type="password" id="repassword" value="" size="32" /></td>
</tr>
<tr><td></td><td><input type="submit" value="确定" /></td></tr>
</table>
</form>
</body>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询