首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2ME开发 >

js checkbox判断一个都没选中submit不跳转,该如何处理

2012-01-05 
js checkbox判断一个都没选中submit不跳转方法一:jsfunction check(){var checkedfalsevar id document

js checkbox判断一个都没选中submit不跳转
方法一:js
  function check(){
var checked=false;
var id= document.getElementsByName("anc_who");
for(var i=0;i<id.length;i++){
if(id[i].checked){
checked=true;
}
}
if(!checked){
alert("请选择要提交的内容");
return false;
}
  }
   


  jsp
  <form action="Announcement_Add" target="InfoIframe" onsubmit="check()">
<table style="border:0px;">
<tr>
<td><input type="checkbox" name="anc_who" value="1" class="checkbox" /> 学生
<input type="checkbox" name="anc_who" value="2" class="checkbox" /> 老师
<input type="checkbox" name="anc_who" value="3" class="checkbox" /> 学生、老师
</td>
</tr>
<tr>
<td><input type="submit" value="确定" /></td>
<td><input type="reset" value="取消" /></td>
</tr>
</table>
</form>
方法二:js
  function check(){
var checked=false;
var id= document.getElementsByName("anc_who");
for(var i=0;i<id.length;i++){
if(id[i].checked){
checked=true;
}
}
if(!checked){
alert("请选择要提交的内容");
return false;
}else{
confirm ("确定要提交吗?");
var form = document.forms['form']; 
form.action="<%=request.getContextPath() %>/Announcement_Add.action";
}
  }
  jsp
  <form action="" target="InfoIframe" onsubmit="check()">
<table style="border:0px;">
<tr>
<td><input type="checkbox" name="anc_who" value="1" class="checkbox" /> 学生
<input type="checkbox" name="anc_who" value="2" class="checkbox" /> 老师
<input type="checkbox" name="anc_who" value="3" class="checkbox" /> 学生、老师
</td>
</tr>
<tr>
<td><input type="submit" value="确定" /></td>
<td><input type="reset" value="取消" /></td>
</tr>
</table>
</form>
两种方法都不可用:第一种是return false后仍然跳转;而第二种return false后则打开又打开一个页面(本页面)

[解决办法]
onsubmit="return check()">

[解决办法]

探讨
onsubmit="return check()">

[解决办法]
<form action="" target="InfoIframe" onsubmit="return check()">

热点排行