怎么样使用jsp中checkbox?
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]);
}
}
本文地址:http://www.45fan.com/bcdm/52116.html