onClick = "return f1()"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyHtml.html</title>
<script language="javaScript">
function f1(){
var email = form1.email.value;
//var pattern = /^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
var pattern = /^[a-zA-Z0-9][a-zA-Z0-9]{2,8}@(163|126)\.(com|cn)$/;
var flag = pattern.test(email);
if(flag){
alert("It's correct!!");
return ture;
}else{
alert("It's incorrect!!");
return flase;
}
}
</script>
</head>
<body>
<form action="login.do" name="form1">
<input type="text" name="email">
<input type="submit" value="确定" onClick="return f1()">
</form>
</body>
</html>
<input type="submit" value="确定" onClick="return f1()">
这样写不管验证对错都会跳到login.do
帮看看吧
--------------------编程问答-------------------- <form action="login.do" name="form1" onsubmit="return f1()">
<input type="text" name="email">
<input type="submit" value="确定">
</form>
--------------------编程问答-------------------- 1楼正解!
还有楼主这个地方貌似写错了
return flase;---->return false;
--------------------编程问答--------------------
正解
或者
<input type="button"
JS里面
if(true){
form1.submit();
} --------------------编程问答-------------------- 1楼解决了 --------------------编程问答-------------------- <html>
<head>
<title>MyHtml.html</title>
<script language="javaScript">
function f1(){
var email = form1.email.value;
//var pattern = /^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
var pattern = /^[a-zA-Z0-9][a-zA-Z0-9]{2,8}@(163|126)\.(com|cn)$/;
var flag = pattern.test(email);
if(flag){
alert("It's correct!!");
return ture;
}else{
alert("It's incorrect!!");
return flase;
}
form1.submit();
}
</script>
</head>
<body>
<form action="login.do" name="form1">
<input type="text" name="email">
<input type="button" value="确定" onClick="return f1()">
</form>
</body>
</html>
submit直接提交了 有事件多用button在func中提交 --------------------编程问答-------------------- submit是什么 是不管怎样都提交,把submit换成button就ok 了 --------------------编程问答-------------------- 这个应该用AJAX吧 不刷新吧 --------------------编程问答-------------------- return flase;应该是
return false;
--------------------编程问答--------------------
1楼的可以,3楼的思路大概对。
最好采用js提交表单,这样的好处,防止网页后退时候,重复提交表单。
补充:Java , Java EE