jquery check box selected, Canceled, select all, no problem

Source: Internet
Author: User
Tags jquery library

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}" > &nbsp; services Create <input id= "Servicecreate" class= "checkb 3 "type=" checkbox "checked=" Checked "name=" Role.servicecreate "value=" 1 "/><br/> &LT;/S:IF&G                    T <s:Else>&nbsp; Services Create <input id= "Servicecreate" class= "checkb3" type= "checkbox" Name= "role.servicecreate" value= "0"/ &GT;&LT;/S:Else><br/> <s:ifTest= "%{#request. R.servicedispatch ==1}" > &nbsp; service Assignment <input id= "servicedispatch" class= "che Ckb3 "type=" checkbox "checked=" Checked "name=" Role.servicedispatch "value=" 1 "/><br/> </s: If> <s:Else>&nbsp; Service Assignment <input id= "Servicedispatch" class= "checkb3" type= "checkbox" Name= "Role.servicedispatch" value= "0"/&GT;&LT;/S:Else><br/> <s:ifTest= "%{#request. R.servicedeal ==1}" > &nbsp; service Handling <input id= "Servicedeal" class= "checkb3" t                    ype= "checkbox" checked= "Checked" name= "Role.servicedeal" value= "1"/><br/> </s:if> <s:Else> &nbsp; Service processing <input id= "Servicedeal" class= "checkb3" type= "checkbox" Name= "role.servicedeal" value= "0"/> &LT;/S:Else><br/> <s:ifTest= "%{#request. R.servicefeedback ==1}" > &nbsp; service Feedback <input id= "servicefeedback" class= "che Ckb3 "type=" checkbox "checked=" Checked "name=" Role.servicefeedback "value=" 1 "/><br/> </s: If> <s:Else>&nbsp; Service Feedback <input id= "Servicefeedback" class= "checkb3" type= "checkbox" Name= "Role.servicefeedback" value= "0"/&GT;&LT;/S:Else><br/> <s:ifTest= "%{#request. R.servicearch ==1}" > &nbsp; service Archive <input id= "Servicearch" class= "checkb3" t                    ype= "checkbox" checked= "Checked" name= "Role.servicearch" value= "1"/><br/> </s:if> <s:Else>&nbsp; Service Archive <input id= "Servicearch" class= "checkb3" type= "checkbox" Name= "Role.servicearch" value= "0"/> &LT;/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.