JS和后台获取复选框(checkbox)选中项后的文本内容
2014-12-13 18:37
656 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> <script language=javascript> //单选与全选的判断 function check(e, allName){ var all = document.getElementsByName(allName)[0]; //获取全选复选框 if(!e.checked){ //没被选中全选复选框置为false; all.checked = false; } else { //选中,遍历数组 var aa = document.getElementsByName(e.name); for (var i=0; i<aa.length; i++) //只要数组中有一个没有选中返回。假如所有的都是选中状态就将全选复选框选中; if(!aa[i].checked) return; all.checked = true; } } //复选框的选择 function checkSub(e, itemName){ var aa = document.getElementsByName(itemName); for (var i=0; i<aa.length; i++){ aa[i].checked = e.checked; } } //发送前检查 function checkItem(itemName){ var aa = document.getElementsByName(itemName); var flag = true; for (var i=0; i<aa.length; i++){ if(aa[i].checked){ alert(r[i].value+","+r[i].nextSibling.nodeValue); flag = false; } } if(flag){ alert("至少选一个"); return true; }else{ sendDBs(); } } var tisub = "first"; function sendDBs(){ if("first"==tisub){ tisub = "other"; document.all.myform.action="<%=path %>/SendDBction.do?method=sendDB"; document.all.myform.submit(); } } </script> </head> <body> <form id="myform" name="myform" method="post" id="myform" action="" > <input name="id" type="checkbox" onclick="check(this, 'checkAll')" value="1"/> 开 <input name="id" type="checkbox" onclick="check(this, 'checkAll')" value="2"/> 开 <input name="id" type="checkbox" onclick="check(this, 'checkAll')" value="3"/> 心 <input name="id" type="checkbox" onclick="check(this, 'checkAll')" value="4"/> 心 <input name="chkAll" type="checkbox" id="chkAll" onclick="CheckAll(this,'id')" value=""/> 全选 <input type="button" onclick="aa('id')" value="选中值"/> </form> </body> </html> </body> </html>
后台获取checkbox的值,只需一句代码:
String[] st = request.getParameterValues("id");即可得到String类型的数组。
若是表单的value值是动态的,并且后台希望获得两个动态值的话,
也即表单<input>如下:<input name="id" type="checkbox" onclick="check(this, 'checkAll')" value="<%=uid%>">
String[] st = request.getParameterValues("id")在后台只能获取uid的数组,现在还想获取uname值,怎么办呢?这是可以再加一个<input />,比如
<input name="id" type="checkbox" onclick="check(this, 'checkAll')" value="<%=uid%>"/> 心
<input name="name" type="hidden" onclick="check(this, 'checkAll')" value="<%=uname%>"/> (隐藏input)
提交表单时<input type="button" onclick="aa('id','name')" value="选中值"/>
在后台
String[] st1 = request.getParameterValues("id");
String[] st2 = request.getParameterValues("name");
相关文章推荐
- JS中获取页面单选框radio和复选框checkbox中当前选中的值
- js获取下拉框的选中值和文本值,后台获取用Request["XXXX"]即可
- js获取checkbox复选框获取选中的选项
- js获取checkbox复选框选中的选项实例
- JS中获取页面单选框radio和复选框checkbox中当前选中的值
- js获取checkbox复选框获取选中的选项
- js获取checkbox中所有选中值及input后面所跟的文本
- js获取checkbox中所有选中值及input后面所跟的文本
- td中内容在竖直方向上居中显示及js获取checkbox是否选中的方式
- js实现复选框全选效果,已经用后台获取选中的复选框的值
- js获取checkbox复选框选中的选项实例
- js获取checkbox中所有选中值及input后面所跟的文本 .
- js获取checkbox复选框获取选中的选项
- js实现前台动态添加文本框,后台获取文本框内容
- js获取下拉列表选中项的值和文本(select)以及获取单选按钮(radio)组的值和修改选中项
- js获取下拉列表选中项的值和文本(select)以及获取单选按钮(radio)组的值和修改选中项
- asp.net CheckBoxList 取值与勾选,复选框后台控制前台checkbox选中
- js取得gridview中获取checkbox选中的值
- Js获取checkboxlist所选中的值
- JS获取下拉列表选中项的值和文本(select)以及获取单选按钮(radio)组的值和修改选中项