Home  >  Article  >  Web Front-end  >  Use javascript to delete all or clear selected operations_javascript skills

Use javascript to delete all or clear selected operations_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:46:421505browse
Copy code The code is as follows:

function deleteAll() {
var all = document.getElementsByName( "checkname");//Get the content you selected is an array
if (all == null || all.length == 1) {
alert("No order yet");
return ;
} else {
var idStr = "";//Define a string of id you want to delete
for ( var i = 0; i < all.length; i ) {
if (all[i].checked) {
idStr = all[i].value ",";//Connect the ids separated by commas
}
}
var result = confirm("Select to delete");
if (result) {
window.location.href = "deleteOrderAction?action=deleteAll&idStr="
idStr;
} else {
return null;
}
}
}


Finally perform business processing
Copy code The code is as follows:

String[] arr = idStr.split(",");//Will get the id string array and use comma split to get each one id
for (String str : arr) {
int orderid = Integer.parseInt(str);
OrderService.deleteOrder(orderid);
}

Summary: The operation of all deletion and clearing is the process of concatenating and splitting strings.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn