JS page jquery code:
Copy Code code as follows:
JavaScript Document
$ (document). Ready (function () {
Select All
$ ("#allChk"). Click (function () {
$ ("Input[name= ' Subchk ']"). Prop ("Checked", this.checked);
});
Radio
var Subchk = $ ("Input[name= ' Subchk ']")
Subchk.click (function () {
$ ("#allChk"). Prop ("checked", subchk.length = = Subchk.filter (": Checked"). length? true:false);
});
/* Bulk Delete * *
$ ("#del_model"). Click (function () {
Determine whether to select at least one item
var checkednum = $ ("input[name= ' Subchk ']:checked"). Length;
if (Checkednum = = 0) {
Alert ("Please select at least one!") ");
Return
}
Batch Selection
if (confirm) (OK to delete the selected item?) ")) {
var checkedlist = new Array ();
$ ("Input[name= ' Subchk ']:checked"). each (function () {
Checkedlist.push ($ (this). Val ());
});
$.ajax ({
Type: "POST",
URL: "Deletemore",
Data: {' Delitems ': checkedlist.tostring ()},
Success:function (Result) {
$ ("[name = ' Subchk ']:checkbox"). attr ("checked", false);
Window.location.reload ();
}
});
}
});
});
page Elements:
<a href= "#" id= "Del_model" ><span> Delete user </span>
<th class= "tal" ><input type= "checkbox" id= "Allchk"/> Full selection </th>
<td><input type= "checkbox" Name= "Subchk" value= "${user.id}"/></td>
callback function, what needs to be done after the request is completed: Here is to remove the selected checkbox (because it is used to freemarker the list cycle, remove the checkbox after the data change, there are the corresponding unknown checkbox was selected, need to remove).
Copy Code code as follows:
Success:function (Result) {
$ ("[name = ' Items ']:checkbox"). attr ("checked", false);
Window.location.reload ();
}
Java Background Code:
Copy Code code as follows:
@RequestMapping (value = "/deletemore", method = Requestmethod.post)
Public String Deletemore (httpservletrequest request, httpservletresponse response) {
String items = Request.getparameter ("Delitems");
string[] Item = Items.split (",");
for (int i = 0; i < item.length; i++) {
Userservice.delete (Integer.parseint (item[i));
}
return "Redirect:list";
}
Effect Chart: