測試頁面: //JS函數(shù)用于全選復(fù)選框 <script type="text/javascript"> function selectAll(form,xx){ var obj=document.forms(form).item(xx); if(obj.length){ for(i=0;i<obj.length;i++){ document.forms(form).item(xx)[i].checked=true; //alert(document.forms(form).item(xx)[i].text); } } else{ obj.checked=true; } } </script> <body> <form name="f1" action="DoUpdateUserServlet" method="post"> <select name="car" onchange="" style="width:180px; margin-left:20px; "> <option selected>=請選擇款項類型=</option> <option value="volvo">volvo</option> <option value="BWM">BWM</option> </select> <input type="radio" name="sex" value="是" /> 是 <input type="radio" name="sex" value="否" /> 否 <br> <input type="checkbox" name="interest" value="trival">trival<br> <input type="checkbox" name="interest" value="music">music<br> <input type="checkbox" name="interest" value="sport">sport<br> <input type="button" value="全選" onclick="selectAll('f1','interest')"> <input type="submit" value="OK"> </form> 在servlet里這樣寫:
// String sex=request.getParameter("sex"); // String car=request.getParameter("car"); // String interest[]=request.getParameterValues("interest"); // System.out.println("car: "+car); // System.out.println("sex: "+sex); // for(int i = 0;i<interest.length;i++) { // System.out.println("interest: "+interest[i]); // } |
|