javascript控制表单提交.pdf
文本预览下载声明
Javascript 控制表单条状,如果表单验证不通过,就阻止跳转,此处没有过多的解释,简单
的代码很容易读取,希望能帮助大家
其中加上了邮箱验证:正则表达式验证
代码页:
%@ page language=java import=java.util.*
pageEncoding=UTF-8%
%
String path = request.getContextPath()
String basePath =
request.getScheme()+://+request.getServerName()+:+request.
getServerPort()+path+/
%
!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
html
head
base href=%=basePath%
titletest page/title
script type=text/javascript
function checkPassword(){
var password =
document.getElementById(password).value
var confirm = document.getElementById(confirm).value
var ff = document.getElementById(ff)
if (password == confirm){
ff.action = aa.jsp
ff.submit()
}else{
document.getElementById(scon).innerHTML = 两次密
码输入不一致
}
}
function checkEmail(){
var email = document.getElementById(email).value
var testEmail =
/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/
if (!testEmail.test(email)){
document.getElementById(semail).innerHTML = 邮箱
格式不正确
}else{
document.getElementById(semail).innerHTML = 邮箱
格式正确
}
}
/script
/head
body
form method=POST id=ff
username:input type=text name=username
id=usernamebr
password:input type=password name=password
id=passwordbr
confirm:input type=password name=confirm
id=confirmspan id=scon/spanbr
email: input type=text name=email id=emial
onblur=checkEmail()span id=semail/spanbr
input type=button value=submit
onclick=checkPassword()
/form
/body
/html
跳转页:
该页面里就随便写入了一句话用来判断跳转正确
下面是随便拷贝的例子,可以借鉴一下
function checkEmail(focu){
var email =
显示全部