JQuery supports full list selection.
You only need a few lines of code to select the list, and can use the post request to execute the background deletion program.
Js
Copy codeThe Code is as follows:
Function DelAlert (data)
{
If (data = 'error ')
{
Alert ("error ~ ");
}
Else if (data = 'success ')
{
Alert ("Success ~ ");
Location. reload ();
}
}
// Introduce jquery. thinkphp is used in the background.
$ (Function (){
// The checkbox of each row must have the check-value attribute to store the id of the current row.
// Select all, And checkAll is the id of all checkboxes. selctone is the class of each row of checkbox.
$ ('# Checkall'). selectall ('selectone ');
// Delete selected, deleteAll is the id of the delete all button selectone is the class background receiving parameter ids format of each row of checkbox, such as: 1, 2, 3
Var url = "Home/Role/delall '";
$ ('# DeleteAll'). delselect ('selectone', url, function (data ){
DelAlert (data );
}, Function (){
Layer. msg ("No selected content", 2, 0 );
});
})
Jquery. selectall. js
Copy codeThe Code is as follows:
(Function ($ ){
$. Fn. selectall = function (className ){
$ (This). bind ('click', function ()
{
If ($ (this). attr ('checked') = 'checked ')
{
$ (This). attr ("checked", false)
$ ('.' + ClassName). attr ('checked', false );
} Else {
$ (This). attr ('checked', 'checked ');
$ ('.' + ClassName). attr ('checked', 'checked ');
}
});
$ ('.' + ClassName). bind ('click', function ()
{
If ($ (this). attr ('checked') = 'checked ')
{
$ (This). attr ("checked", false );
} Else {
$ (This). attr ('checked', 'checked ');
}
});
};
$. Fn. delselect = function (className, url, fun, unselectfun ){
$ (This). bind ('click', function (){
Var selectid = '';
$ ("." + ClassName). each (function (){
If ($ (this). attr ('checked') = 'checked '){
Selectid + = $ (this). attr ('check-value') + ',';
}
});
If (selectid)
{
Selectid = selectid. substring (0, selectid. length-1 );
$. Post (url, {ids: selectid}, function (data ){
Fun (data );
});
} Else
{
Unselectfun ();
}
});
};
}) (JQuery );
The above is all the content of this article. I hope you will like it.