Jquery checkbox checkbox implements delete before judging
- 2020-03-30 02:40:13
- OfStack
To achieve such a basic requirement, the page has a lot of data, you can delete one or more, delete before the judge is selected at least one, otherwise prompt.
Background action to receive data for deletion
function deleteUser() {
//I wanted to save the contents as STR +="", but I couldn't
//var str;
var array = new Array(); //The ID used to hold the selected piece of data
var flag; //Determine if one is not selected
$("input[name='selectFlag']:checkbox").each(function() { //Iterate over all checkboxes whose name is selectFlag
if ($(this).attr("checked")) { //Decide whether to select
flag = true; //As long as one is selected and set to true
}
})
if (flag) {
$("input[name='selectFlag']:checkbox").each(function() { //Iterate over all checkboxes whose name is selectFlag
if ($(this).attr("checked")) { //Decide whether to select
//alert($(this).val());
array.push($(this).val()); //Adds the selected value to the array
//str+=$(this).val()+",";
}
})
//The data to be collectively deleted is passed to the action for processing
window.self.location = "deleteUser?info=" + array;
} else {
alert(" Please select at least one user ");
}
}
Background action to receive data for deletion
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
//The foreground is a,b,c format for the transmission of the first decomposed string
String s[] = info.split(",");
if (s.length > 0) {
for (int i = 0; i < s.length; i++) {
userDao.deleteUser(s[i]);
}
}
return "success";
}