Home > Web Front-end > JS Tutorial > jQuery implements the select all function of the list_jquery

jQuery implements the select all function of the list_jquery

WBOY
Release: 2016-05-16 16:08:41
Original
1577 people have browsed it

Only a few lines of code are needed to realize the full selection function of the list, and the background deletion program can be executed in conjunction with the post request

js

Copy code The code is as follows:

function DelAlert(data)
{
If(data == 'error')
            {
alert("Error~");
}
          else if(data == 'success')
            {
alert("Success~");
location.reload();
}
}
//Introducing jquery, the backend here is thinkphp
$(function(){
//The checkbox of each row needs to have a check-value attribute to store the id of the current row
//Select all, checkAll is the id of the checkbox that selects all, selctone is the class of each row of checkbox
          $('#checkAll').selectall('selectone');
// Delete the selection, deleteall to delete all the buttons of the ID selectone to receive the parameter IDS format for each line of checkbox.         var url = "Home/Role/delall'";
           $('#deleteAll').delselect('selectone',url,function(data){
               DelAlert(data);
          },function(){
              layer.msg("No content selected",2,0);
        });
})

jquery.selectall.js

Copy code The 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 );

以上所述就是本文的全部内容了,希望大家能够喜欢。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template