First, the jquery library must be introduced:
Here is the JS code:
/** * service management block >>> check box event handling*/ //Service Management check box is selected, canceled
$ (function () {
$ ("#ServiceManageMent"). Click (function(){ if( This. Checked) { $(". Checkb3"). each (function(){ This. checked =true; $( This). Val (1); }); }Else{ $(". Checkb3"). each (function(){ This. checked =false; $( This). val (0); }); } }); //service creation is selected, canceled$ ("#serviceCreate, #serviceDispatch, #serviceDeal, #serviceArch, #serviceFeedback"). Click (function(){ var$serviceCreate = $ ("#serviceCreate"). Is (": Checked"); var$serviceDispatch = $ ("#serviceDispatch"). Is (": Checked"); var$serviceDeal = $ ("#serviceDeal"). Is (": Checked"); var$serviceFeedback = $ ("#serviceFeedback"). Is (": Checked"); var$serviceArch = $ ("#serviceArch"). Is (": Checked"); if( This. Checked) { //If service creation is selected, determine if the other check boxes are selected, and if they are selected, change the selected state of service management if($serviceCreate) {$ ("#serviceCreate"). Val (1); }Else{ $("#serviceCreate"). Val (0); } if($serviceDispatch) {$ ("#serviceDispatch"). Val (1); }Else{ $("#serviceDispatch"). Val (0); } if($serviceDeal) {$ ("#serviceDeal"). Val (1); }Else{ $("#serviceDeal"). Val (0); } if($serviceFeedback) {$ ("#serviceFeedback"). Val (1); }Else{ $("#serviceFeedback"). Val (0); } if($serviceArch) {$ ("#serviceArch"). Val (1); }Else{ $("#serviceArch"). Val (0); } if($serviceCreate && $serviceDispatch && $serviceDeal && $serviceFeedback &&$serviceArch) { $("#ServiceManageMent"). each (function(){ This. checked =true; }); }Else{ $("#ServiceManageMent"). each (function(){ This. checked =false; }); } }Else{ $( This). val (0); $("#ServiceManageMent"). each (function(){ This. checked =false; }); } });
});
JSP page Core code:
Service Management <input id= "servicemanagement" class= "checkb" type= "checkbox"/><br/> <s:ifTest= "%{#request. R.servicecreate ==1}" > services Create <input id= "Servicecreate" class= "checkb 3 "type=" checkbox "checked=" Checked "name=" Role.servicecreate "value=" 1 "/><br/> </S:IF&G T <s:Else> Services Create <input id= "Servicecreate" class= "checkb3" type= "checkbox" Name= "role.servicecreate" value= "0"/ ></S:Else><br/> <s:ifTest= "%{#request. R.servicedispatch ==1}" > service Assignment <input id= "servicedispatch" class= "che Ckb3 "type=" checkbox "checked=" Checked "name=" Role.servicedispatch "value=" 1 "/><br/> </s: If> <s:Else> Service Assignment <input id= "Servicedispatch" class= "checkb3" type= "checkbox" Name= "Role.servicedispatch" value= "0"/></S:Else><br/> <s:ifTest= "%{#request. R.servicedeal ==1}" > service Handling <input id= "Servicedeal" class= "checkb3" t ype= "checkbox" checked= "Checked" name= "Role.servicedeal" value= "1"/><br/> </s:if> <s:Else> Service processing <input id= "Servicedeal" class= "checkb3" type= "checkbox" Name= "role.servicedeal" value= "0"/> </S:Else><br/> <s:ifTest= "%{#request. R.servicefeedback ==1}" > service Feedback <input id= "servicefeedback" class= "che Ckb3 "type=" checkbox "checked=" Checked "name=" Role.servicefeedback "value=" 1 "/><br/> </s: If> <s:Else> Service Feedback <input id= "Servicefeedback" class= "checkb3" type= "checkbox" Name= "Role.servicefeedback" value= "0"/></S:Else><br/> <s:ifTest= "%{#request. R.servicearch ==1}" > service Archive <input id= "Servicearch" class= "checkb3" t ype= "checkbox" checked= "Checked" name= "Role.servicearch" value= "1"/><br/> </s:if> <s:Else> Service Archive <input id= "Servicearch" class= "checkb3" type= "checkbox" Name= "Role.servicearch" value= "0"/> </S:Else><br/>
Notes:
jsp file, you will see " <s:if test="%{#request. R.servicecreate ==1} ">" This code, do not doubt, This is the label and expression of Struts2,
Ignore it, though the code is a little bit heavier in thought. Each road God, please give more advice!
jquery check box selected, Canceled, select all, no problem