JQuery supports full list selection.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.