Use javascript to delete or empty all selected operations
- 2020-03-30 03:06:49
- OfStack
function deleteAll() {
var all = document.getElementsByName("checkname");//Getting what you selected is an array
if (all == null || all.length == 1) {
alert(" No orders ");
return;
} else {
var idStr = "";//Defines a string of ids that you want to delete
for ( var i = 0; i < all.length; i++) {
if (all[i].checked) {
idStr += all[i].value + ",";//Connect the ids with commas, separating them
}
}
var result = confirm(" Delete selected ");
if (result) {
window.location.href = "deleteOrderAction?action=deleteAll&idStr="
+ idStr;
} else {
return null;
}
}
}
</script>
Finally, business processing
String[] arr = idStr.split(",");//An array of obtained id strings is split for each id using a comma
for (String str : arr) {
int orderid = Integer.parseInt(str);
OrderService.deleteOrder(orderid);
}
Summary: the operation of all delete and empty is the process of string splicing and splitting.