日期:2014-05-16  浏览次数:20440 次

form只响应onclick不响应onsubmit
以下代码点点击submit后不响应,点击reset后也不响应。把form里的"onsubmit"改成"onclick"后有响应,但不管点击输入框还是两个按扭都同样响应。。。。求解

<%@ page language="java" contentType="text/html; charset=gb2312"
  pageEncoding="gb2312"%>
<script type="text/javascript">
<!--
function sub() {
if(form1.name.value==""||form1.name.value==null){
alert("name cant empty");
form1.name.focus();
return false;
}
if(form1.pass.value==""||form1.pass.value==null){
alert("pass cant empty");
form1.pass.focus();
return false;
}
return true;
}
//-->
</script>
<!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=gb2312">
<title>Insert title here</title>

</head>
<body>
<form action="login1.jsp" method="post" name="form1" onsubmit="return sub();">
name:<input type="text" name="name"><br>
pass:<input type="text" name="pass"><br>
<input type="button" name="submit" value="submit">
<input type="button" name="reset" value="reset">
</form>
</body>
</html>

------解决方案--------------------
<input type="button" name="submit" value="submit">

把type的值,“button”改成“submit”
reset类似,把“button”改成““reset”

这是控件类型的问题,楼主还是去查一下input标签的type属性的分类吧~~