Js page jquery code:
Copy codeThe Code is as follows:
// JavaScript Document
$ (Document). ready (function (){
// Select all
$ ("# AllChk"). click (function (){
$ ("Input [name = 'subchk']"). prop ("checked", this. checked );
});
// Single answer
Var subChk = $ ("input [name = 'subchk']")
SubChk. click (function (){
$ ("# AllChk"). prop ("checked", subChk. length = subChk. filter (": checked"). length? True: false );
});
/* Batch Delete */
$ ("# Del_model"). click (function (){
// Determine if at least one item is selected
Var checkedNum = $ ("input [name = 'subchk']: checked"). length;
If (checkedNum = 0 ){
Alert ("select at least one item! ");
Return;
}
// Batch select
If (confirm ("are you sure you want to delete the selected project? ")){
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 a user </span>
<Th class = "tal"> <input type = "checkbox" id = "allChk"/> select all </th>
<Td> <input type = "checkbox" name = "subChk" value = "$ {user. id}"/> </td>
The operation that needs to be performed after the request is completed. Here, the checkbox is removed (because the list loop of freemarker is used, and the checkbox sequence number changes after the data is removed, there are also unknown checkboxes selected and need to be removed ).
Copy codeThe Code is as follows:
Success: function (result ){
$ ("[Name = 'items ']: checkbox"). attr ("checked", false );
Window. location. reload ();
}
Java background code:
Copy codeThe Code is 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 ";
}
: