在js中写了返回false 为什么还能提交表单
<body><h1>注册<ahref="login.jsp">返回登录</a></h1><formaction="insertStuServ"method="post"o...
<body>
<h1>注册<a href="login.jsp">返回登录</a></h1>
<form action="insertStuServ" method="post" onsubmit="return vali()">
<p><lable for="studentNo">学 号:</lable>
<input autocomplete="off" type="text" name="studentNo" id="studnetNo"/>
</p>
<p><lable for="studentName">姓 名:</lable>
<input autocomplete="off" type="text" name="studentName" id="studnetName"/>
</p>
<p><lable for="studentPwd">密 码:</lable>
<input type="password" name="studentPwd" id="studnetPwd"/>
</p>
<p><lable for="studentPwdConfirm">确认密码:</lable>
<input type="password" name="studentPwdConfirm" id="studentPwdConfirm"/>
</p>
<p><lable for="department">学 院:</lable>
<select autocomplete="off" name="department" id="department" onchange="changeDepart(this)">
<option value="">===请选择学院===</option>
<%
for(DepartmentInfo d:list){
%><option value="<%=d.getDepartmentNo()%>"><%= d.getDepartmentName() %></option><%
}
%>
</select>
</p>
<p><lable for="belongClassNo">班 级:</lable>
<select autocomplete="off" name="belongClassNo" id="belongClassNo" >
<option value="">===请选择班级===</option>
</select>
</p>
<p><lable ></lable>
<input type="submit" value="提交"/>
</p>
</form>
<form id="myForm" class="hidden" action="regServ" method="get" target="ifr">
<input name="belongDepartment" id ="belongDepartment"/>
<input name="action" value="queryClass"/>
</form>
<iframe class="hidden" name="ifr" id="ifr" ></iframe>
<script type="text/javascript">
function changeDepart(obj){
document.getElementById("belongClassNo").innerHTML="";
if(obj.value=="")return;
document.getElementById("belongDepartment").value=obj.value;
try{
document.getElementById("myForm").submit();
}catch(e){alert(e)}
}
function setClass(s){
document.getElementById("belongClassNo").innerHTML=s;
//jquery obj.html(); obj.append();
}
function vali(){
var fields={"studentNo":"学号","studentName":"姓名","studentPwd":"密码","belongClassNo":"班级"};
for(var k in fields){
if(document.getElementById(k).value=""){
alert(fields[k]+"不能为空!");
return false;
}
}
if(document.getElementById("studentPwd").value!=document.getElementById("studentPwdConfirm").value){
alert("两次输入的密码不一致!");
return false;
}
return false;
}
</script>
</body>
</html> 展开
<h1>注册<a href="login.jsp">返回登录</a></h1>
<form action="insertStuServ" method="post" onsubmit="return vali()">
<p><lable for="studentNo">学 号:</lable>
<input autocomplete="off" type="text" name="studentNo" id="studnetNo"/>
</p>
<p><lable for="studentName">姓 名:</lable>
<input autocomplete="off" type="text" name="studentName" id="studnetName"/>
</p>
<p><lable for="studentPwd">密 码:</lable>
<input type="password" name="studentPwd" id="studnetPwd"/>
</p>
<p><lable for="studentPwdConfirm">确认密码:</lable>
<input type="password" name="studentPwdConfirm" id="studentPwdConfirm"/>
</p>
<p><lable for="department">学 院:</lable>
<select autocomplete="off" name="department" id="department" onchange="changeDepart(this)">
<option value="">===请选择学院===</option>
<%
for(DepartmentInfo d:list){
%><option value="<%=d.getDepartmentNo()%>"><%= d.getDepartmentName() %></option><%
}
%>
</select>
</p>
<p><lable for="belongClassNo">班 级:</lable>
<select autocomplete="off" name="belongClassNo" id="belongClassNo" >
<option value="">===请选择班级===</option>
</select>
</p>
<p><lable ></lable>
<input type="submit" value="提交"/>
</p>
</form>
<form id="myForm" class="hidden" action="regServ" method="get" target="ifr">
<input name="belongDepartment" id ="belongDepartment"/>
<input name="action" value="queryClass"/>
</form>
<iframe class="hidden" name="ifr" id="ifr" ></iframe>
<script type="text/javascript">
function changeDepart(obj){
document.getElementById("belongClassNo").innerHTML="";
if(obj.value=="")return;
document.getElementById("belongDepartment").value=obj.value;
try{
document.getElementById("myForm").submit();
}catch(e){alert(e)}
}
function setClass(s){
document.getElementById("belongClassNo").innerHTML=s;
//jquery obj.html(); obj.append();
}
function vali(){
var fields={"studentNo":"学号","studentName":"姓名","studentPwd":"密码","belongClassNo":"班级"};
for(var k in fields){
if(document.getElementById(k).value=""){
alert(fields[k]+"不能为空!");
return false;
}
}
if(document.getElementById("studentPwd").value!=document.getElementById("studentPwdConfirm").value){
alert("两次输入的密码不一致!");
return false;
}
return false;
}
</script>
</body>
</html> 展开
1个回答
2017-06-21
展开全部
form标签里增加onsubmit事件,return false; 或者你这样调用验证onsubmit="return check()", c
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |