Home >Web Front-end >JS Tutorial >jquery checkbox checkbox realizes judgment before deletion_jquery

jquery checkbox checkbox realizes judgment before deletion_jquery

WBOY
WBOYOriginal
2016-05-16 16:51:591051browse

To achieve such a basic requirement, the page has a lot of data. You can delete one or more items. Before deleting, check whether at least one item is selected, otherwise you will be prompted.

Copy code The code is as follows:

function deleteUser() {
//At that time it was I want to save the content as str ="", but it doesn't work
//var str;
var array = new Array(); //The ID used to save the selected piece of data
var flag; //Determine whether an unselected one is
$("input[name='selectFlag']:checkbox").each(function() { //Traverse all checkboxes whose name is selectFlag
if ($ (this).attr("checked")) { //Determine whether it is selected
flag = true; //As long as one is selected, set it to true
}
})
if (flag) {
$("input[name='selectFlag']:checkbox").each(function() { //Traverse all checkboxes whose name is selectFlag
if ($(this).attr("checked ")) { //Determine whether it is selected
//alert($(this).val());
array.push($(this).val()); //Add the selected value into array
//str =$(this).val() ",";
}
})
//Pass the data to be collectively deleted to action processing
window. self.location = "deleteUser?info=" array;
} else {
alert("Please select at least one user");
}
}

Backend action to receive data and delete it
Copy code The code is as follows:

@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
//The frontend is transmitted in a, b, c format. First decompose the string
String s[] = info.split (",");
/*
* for(int i=0;i*/
if (s.length > 0) {
for (int i = 0; i < s.length; i ) {
userDao.deleteUser(s[i]);
}
}
return "success";
}
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