表单type:image提交Js阻止问题?有测试页
<%@ 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%> ">
<title> My JSP 'imageSub.jsp ' starting page </title>
<meta http-equiv= "pragma " content= "no-cache ">
<meta http-equiv= "cache-control " content= "no-cache ">
<meta http-equiv= "expires " content= "0 ">
<meta http-equiv= "keywords " content= "keyword1,keyword2,keyword3 ">
<meta http-equiv= "description " content= "This is my page ">
<!--
<link rel= "stylesheet " type= "text/css " href= "styles.css ">
-->
<script>
function checkInput(s)
{
var reg=new RegExp( "^[\da-zA-Z0-9\u4e00-\u9fa5]*$ ", "g ");
var rs=s.search(reg);
if(rs==-1)
return false;
else
return true;
}
function formsub()
{
var v=document.getElementById( 'sear ').value;
var flag=checkInput(v);
if(flag)
{
document.getElementById( 'f ').submit();
return true;
}
else
{
return false;
}
}
</script>
</head>
<body>
<form id= "f " action= "App/imageSub.jsp " method= "POST ">
<dl>
<dt>
<input class= "input " type= "text " id= 'sear ' name= 'sear ' value= "文本 " />
</dt>
<dt>
<!-- <input type= "button " src= "http://www.csdn.net/ui/scripts/Csdn/_resources/FrameMDI/forum.gif " onclick= "formsub() " /> -->
<input type= "image " src= "http://www.csdn.net/ui/scripts/Csdn/_resources/FrameMDI/forum.gif " onclick= "formsub() " />
<!-- 改变这两个input 一个是type:button 一个是type:image 当是前者时,表单提交前需要返回值为true,当是后者时,不论返回值是true/false 表单都提交,现在要求用type:image时,可以通过Js事件按条件阻止提交 PS:可以观察状态栏进度条判断是否提交 -->
</dt>
</dl>
</form>
</body>
</html>
=======================================================
type:button
type:image
提交时Javascript能否阻止submit()的问题
------解决方案--------------------onclick= "return formsub() "