复选框 选择 全选

页面:

<td align="right">使用状态: <input type="checkbox" name="checkBox2"  onClick="selectAll('serviceModes','checkBox2')" title="全部选中或取消选中"/>
     </td>
  <td width="30%">
      <bean:define id="serviceMode" name="hardWareForm" property="serviceModeList"/>
          <html:select name="hardWareForm" property="serviceModes" multiple="true"  size="5" style="width:95%">
        <html:options collection="serviceMode" property="key" labelProperty="value" />
          </html:select>
      </td>

 

脚本:

//全选
function selectAll(s,boxname){
 var checked = false;
 var box = document.getElementById(boxname);
 if(box.checked){
  checked = true;
 }
 var b = document.getElementById(s);
 for(var i=0;i<b.length;i++){
        b[i].selected=checked;
 }
}

 

var serviceModes = document.getElementById("serviceModes");
 for(var i=0;i<serviceModes .length;i++){
   if(serviceModes [i].selected){
  if(checkValues=="" || checkValues==null){
    checkValues = serviceModes [i].value; 
   }else{
    checkValues += "," + serviceModes [i].value;
  }
  }
  }

 

在action中直接获取

String[] serviceModes = (String[]) request
     .getAttribute("serviceModes");

 

你可能感兴趣的:(html,bean,脚本)