checkbox class:
1. Full Select function for checkbox
<script type= "Text/javascript" >//all selected Checkbox:1, when the Select checkbox is checked, the sub-checkbox (name is ' IDs ' checkbox) automatically all tick//2, When the Select checkbox is unchecked, the sub-checkbox automatically uncheck all function Checkall () { if ("#checkall") [0].checked) { $ ("Input[type = ' checkbox '][name= ' IDs '). attr ("Checked", "checked"); } else{ $ ("input[type= ' checkbox '][name= ' IDs ']"). attr ("checked", null);} } Sub-checkbox:1, when all sub-checkboxes are checked, the Select checkbox is automatically checked//2, when a sub-checkbox is not checked, the Select checkbox is automatically changed to uncheck function Changecheckcount () { var count=0; $ ("input[type= ' checkbox '][name= ' IDs ']"). each (function (index,data) { if (this.checked) { count++; } }); if (count== $ ("input[type= ' checkbox '][name= ' IDs '"). Length) { $ ("#checkall"). attr ("Checked", "checked") ; } else{ $ ("#checkall"). attr ("checked", null);} } </script>
<td><!--Select all checkbox--><s:checkbox name= "Checkall" id= "Checkall" value= "cssclass=" checkbox "onclick= "Checkall ()"/></td><td><!--Child checkbox-- <s:checkbox name= "IDs" fieldvalue= "" cssclass= "checkbox" onclick= "Changecheckcount ()"/> <s:checkbox name= "IDs" fieldvalue= "cssclass=" CheckBox "onclick=" Changecheckcount () "/> <s:checkbox name=" IDs " fieldvalue=" "Cssclass=" checkbox " Onclick= "Changecheckcount ()"/> <s:checkbox name= "IDs" fieldvalue= "cssclass=" checkbox "onclick=" Changecheckcount () "/></td>
2. Get the number of checkboxes selected and organize the values of the checkbox into strings
<script type= "Text/javascript" >//1, gets the number of checkboxes selected: COUNT//2, the value of the selected checkbox (this example is ID) is organized into a string of type "Id,id,id,..." , Easy action access: Idsfunction checkbox () { var count=0; var ids= ""; $ ("input[type= ' checkbox '][name= ' IDs ']"). each (function (index,data) { if (this.checked) { count++; if (count==1) { ids=$ (this). Val (); } else{ ids=ids+ "," +$ (This). Val (); } }
<td> <s:checkbox name= "IDs" fieldvalue= "cssclass=" checkbox " /> <s:checkbox Name= "IDs" fieldvalue= "cssclass=" checkbox ""/> <s:checkbox name= "IDs" fieldvalue= "" cssclass= "checkbox" "/> <s:checkbox name=" IDs " fieldvalue=" "cssclass=" checkbox "/></td>
Select Class
1.jQuery implementation of pull-down list linkage, to achieve province and City Association
<script type= "Text/javascript" >//implementation of the province and city level two linkage/*jquery.post (URL, [data], [callback], [type]): Use post to make asynchronous requests, [] is an optional attribute, this example selected the [data],[callback] parameter: URL (String): The URL address of the sending request. Data (MAP): (optional) The information to be sent to the server, expressed as a Key/value key-value pair. Callback (function): (optional) The callback function when loading succeeds (the method is called only if the return state of response is success). Type (String): (optional) The official description is: Type of data to be sent. The type that should actually be requested for the client (Json,xml, and so on) */function showcity (value) {///through the Showcity function in action to get the list of cities in the corresponding province by province name and return the corresponding data//{name : Value}:value Province name $.post ("${pagecontext.request.contextpath}/company_showcity.action", {name:value}, for the province drop-down list). function (data,textstatuts) {//alert (data); var dataobj=eval ("(" +data+ ")"); alert (dataobj); First, delete the city $ ("select[name=" option[value!= "]") that was previously loaded. Remove (); Package the city into option and add to the Select, formatted as follows//<select name= "Cities" style= "width:90%" >//<option value = "" >--------</option>//</seleCt> for (Var i=0;i<dataobj.length;i++) {var $option =$ ("<option></option>"); $option. attr ("value", dataobj[i].name); $option. Text (dataobj[i].name); $ ("Select[name= ' city ']"). Append ($option); } });} </script>
<tr><td> province:</td><td> <s:select list= "#provinceList" name= "province" id= "province" listkey= "name" listvalue= "name" headerkey= "headervalue="--------" cssstyle=" width:90% "onchange=" Showcity (this.value) "> </s:select></td><td> City:</td><td> <s:select List= "{}" Name= "City" id= "City" headerkey= "headervalue="--------"cssstyle=" width:90% "> </s:select ></td></tr>
the showcity function in Company.action
/** shows the corresponding city by province * @throws ioexception **/public string showcity () throws ioexception{//get the name of the province in the JSP string name= Request.getparameter ("name"), if (Stringutils.isnotblank (name)) {//By province name to the corresponding province entity (when querying the city, to take the province id) province Province=provinceservice.findprovincebyname (name);//Search all cities under the province by province ID list<city> citylist= Cityservice.findcitybypid (Province.getid ());//new a jsonconfigjsonconfig config=new jsonconfig ();//Set not to get the property column, Only the Name property of the city table is taken, according to the city tables you define, Config.setexcludes (new string[]{"id", "Pycode", "pid", "Postcode", "AreaCode"});// Convert list to Jsonarrayjsonarray jsonarray=jsonarray.fromobject (citylist,config); Response.setcharacterencoding ("Utf-8 ");//Convert Jsonarray to a string and send it to the JSP page Response.getwriter (). Print (jsonarray.tostring ()); return null;}