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]);
}
}