日期:2014-05-17 浏览次数:20727 次
<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>注册</title> </head> <body> <form id="form1" name="form1" method="post" action="show.jsp"> <label>用户名: <input type="text" name="name"> </label> <p> <label>密码: <input type="password" name="pw"> </label> </p> <p> <label>再次输入密码: <input type="password" name="rpw"> </label> </p> <p> <label>邮箱: <input type="text" name="email" > </label> </p> <p> <input type="submit" name="提交" > </p> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>注册</title> </head> <body> <form id="form1" name="form1" method="post" action="show.jsp" onsubmit="var f=document.getElementById('form1'); return f.pw === f.rpw ? true : alert('error'),false;"> <label>用户名: <input type="text" name="name"> </label> <p> <label>密码: <input type="password" name="pw"> </label> </p> <p> <label>再次输入密码: <input type="password" name="rpw"> </label> </p> <p> <label>邮箱: <input type="text" name="email" > </label> </p> <p> <input type="submit" name="提交" > </p> </form> </body> </html>
------解决方案--------------------
JS可以判断,也可以表单2个password提交后台改。
------解决方案--------------------
可以通过js来判断,两次输入的密码是否相同,如果成功,在commit();
把提交按钮该写成
<input type="button" onclick="isSamePassword()" value="确认"/>
js代码:
<script type="text/javascript">
function isSamePassword(){
var passwordOne,passwordTwo;
passwordOne = document.getElementById("pw").value;
passwordTwo = document.getElementById("rpw").value;
if(passwordOne ==passwordTwo ){
alert("ok!");
form1.submit();
}else{
alert("两次输入密码不一致请重新输入!");
}
}
</script>
------解决方案--------------------
JS判断:
<script type="text/javascript">