jsp中checkbox用法详解
程序员文章站
2022-10-31 13:49:14
string[] picked = request.getparametervalues("open");
if (picked != null) {...
string[] picked = request.getparametervalues("open"); if (picked != null) { for (int i = 0;i < picked.length; i++) { // system.out.println("11"+picked[i]); udao.getcheckopen( picked[i]); } }
今天怀着惶恐的心情用了下checkbox,一直以为挺神秘的东西,可是当你决定静下心来要把它搞定的时候,才发现事情远没有想象中困难o(∩_∩)o~
*****************************************************************************************************
从网上找的理论:
(获取checkbox中的值)
string[] picked = request.getparametervalues("colname"); string[] a=new string[20]; if (picked != null) { for (int i = 0;i < picked.length; i++) { out.println(" "+picked[i]); } else { out.println ("none"); }
如何jsp页面checkbox实现全选.
用javascript吧。
<html> <body> <script> function kk(){ var handleel = document.getelementbyid("kkhandler"); var els = document.getelementsbyname("kk"); for(i=0;i<els.length;i++){ els[i].checked = handleel.checked; } } </script> <input type=checkbox onclick="kk()" name="kkhandler">全选<br> <input type=checkbox name="kk"> <input type=checkbox name="kk"> </body> </html>
2:
<form name="form" id="form1"> <input type="checkbox" name="id" value="" id="checkbox1">1 <input type="checkbox" name="id" value="" id="checkbox2">2 <input type="checkbox" name="chose" value="" onclick="selectall()" id="checkbox5">allselect </form> <script> function selectall() { if(!document.form.id.length){ if(document.form.chose.checked){ document.form.id.checked=true; } else{ document.form.id.checked=false; } } else{ for(var i=0;i<document.form.id.length;i++){ if(document.form.chose.checked){ document.form.id[i].checked=true; } else{ document.form.id[i].checked=false; } } } } </script>
******************************************************************************************************
我的代码
jsp页面代码:
<script language = "javascript"> <!-- function selectall() { if(!document.form.open.length){ if(document.form.chose.checked){ document.form.open.checked=true; } else{ document.form.open.checked=false; } } else{ for(var i=0;i<document.form.open.length;i++){ if(document.form.chose.checked){ document.form.open[i].checked=true; } else{ document.form.open[i].checked=false; } } } } --> </script> <logic:present name="infor"> <logic:iterate id="show" name="infor"> <tr bgcolor = '#e7f1fe'> <td width="5%"> <logic:equal value="未开通" name="show" property="status"> <input type="checkbox" name="open" value="<bean:write name="show" property="legalpersoncode" />"> </logic:equal>
action 里面的写法:
string[] picked = request.getparametervalues("open");
if (picked != null) {
for (int i = 0;i < picked.length; i++) {
// system.out.println("11"+picked[i]);
udao.getcheckopen( picked[i]);
}
}