第一次使用复选框

第一次使用复选框

box.html:

< body >
< form  action ="box.jsp"  method ="post" >
  
< p >
  
< input  name ="box"  type ="checkbox"   value ="box1"   />
  box1
  
</ p >
  
< p >
    
< input  name ="box"  type ="checkbox"   value ="box2"   />
  box2
</ p >
  
< p >
    
< input  name ="box"  type ="checkbox"   value ="box3"   />
  box3
</ p >
  
< p >
    
< label >
    
< input  type ="submit"  name ="Submit"  value ="提交"   />
    
</ label >     
    
</ p >
</ form >
</ body >

box.jsp:

<%
String[] box=request.getParameterValues("box");
    
for(String b:box){
        out.print(b
+"<br/>");
    }
%>

显示为:

box1
box2
box3

  在form中的checkbox的name属性都写成同一个名字:box ,然后在用request.getParameter Values() 取到一个String[]。(注:不是request.getParameter())

  还有一个问题没有解决,“ 选择全部”问题,想法是用jquery来完成。

你可能感兴趣的:(第一次使用复选框)