最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery實現(xiàn)列表的全選功能

 更新時間:2015年03月18日 11:20:47   投稿:hebedich  
本文給大家分享的是使用jquery實現(xiàn)的全選刪除插件的代碼,非常的實用,本文示例是結(jié)合的ThinkPHP,小伙伴們可以自由擴展。

只需要幾行代碼就可以實現(xiàn)列表的全選功能,并且可以配合post請求執(zhí)行后臺的刪除程序

js

復(fù)制代碼 代碼如下:

function DelAlert(data)
    {
        if(data == 'error')
        {
            alert("錯誤~");
        }
        else if(data == 'success')
        {
            alert("成功~");
            location.reload();
        }
    }
    //引入jquery,這里后臺配合的是thinkphp
    $(function(){
        //每行的checkbox需要有check-value屬性來存放當前行的id
        //選中全部,checkAll 為選中全部的checkbox的id selctone 為每一行checkbox的class
        $('#checkAll').selectall('selectone');
        //刪除選中,deleteAll為刪除全部按鈕的id  selectone 為每一行checkbox的class 后臺接收參數(shù)ids 格式如: 1,2,3
        var url = "Home/Role/delall'";
        $('#deleteAll').delselect('selectone',url,function(data){
            DelAlert(data);
        },function(){
            layer.msg("沒有選中內(nèi)容",2,0);
        });
    })

jquery.selectall.js

復(fù)制代碼 代碼如下:

(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 );

以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。

相關(guān)文章

最新評論

义乌市| 谢通门县| 马山县| 得荣县| 华容县| 康乐县| 泰来县| 谢通门县| 蒲城县| 翼城县| 修水县| 滨州市| 蛟河市| 商城县| 旺苍县| 湟中县| 子长县| 襄樊市| 汕尾市| 宜阳县| 福鼎市| 绥芬河市| 莆田市| 玉环县| 平顺县| 通州区| 刚察县| 长乐市| 迭部县| 绥棱县| 台北市| 邮箱| 东乡族自治县| 都兰县| 通化市| 宕昌县| 南部县| 天祝| 化州市| 新巴尔虎右旗| 永嘉县|