To achieve this basic requirement, there is a lot of data on the page, you can delete one or more items, determine whether to select at least one before deletion, otherwise the prompt is displayed.
Copy codeThe Code is as follows:
Function deleteUser (){
// At that time, I wanted to save the content in the str + = "" format, but I couldn't
// Var str;
Var array = new Array (); // ID used to save the selected data
Var flag; // determines whether an unselected
$ ("Input [name = 'selectflag']: checkbox"). each (function () {// traverse all checkboxes whose names are selectFlag
If ($ (this). attr ("checked") {// determines whether to select
Flag = true; // if either of them is selected as true
}
})
If (flag ){
$ ("Input [name = 'selectflag']: checkbox"). each (function () {// traverse all checkboxes whose names are selectFlag
If ($ (this). attr ("checked") {// determines whether to select
// Alert ($ (this). val ());
Array. push ($ (this). val (); // Add the selected value to the array.
// Str + = $ (this). val () + ",";
}
})
// Pass the data to be deleted to action for processing
Window. self. location = "deleteUser? Info = "+ array;
} Else {
Alert ("select at least one user ");
}
}
The background action is used to delete the received data.
Copy codeThe Code is as follows:
@ Override
Public String execute () throws Exception {
// TODO Auto-generated method stub
// The front-end is transmitted in the format of a, B, and c. The string is first decomposed.
String s [] = info. split (",");
/*
* For (int I = 0; I <s. length; I ++) {System. out. println (s [I]);}
*/
If (s. length> 0 ){
For (int I = 0; I <s. length; I ++ ){
UserDao. deleteUser (s [I]);
}
}
Return "success ";
}