php 列表全选,jQuery实现列表的全选功能_jquery

这篇博客介绍了如何利用jQuery实现列表的全选功能和配合POST请求进行后台删除操作。通过绑定事件和自定义函数,实现了选中全部项、删除选中项的功能,并提供了错误和成功提示。示例代码中,`selectall`和`delselect`方法用于全选和删除操作,`DelAlert`函数处理后台返回的删除结果。
摘要由CSDN通过智能技术生成

只需要几行代码就可以实现列表的全选功能,并且可以配合post请求执行后台的删除程序

js

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 后台接收参数ids 格式如: 1,2,3

var url = "Home/Role/delall'";

$('#deleteAll').delselect('selectone',url,function(data){

DelAlert(data);

},function(){

layer.msg("没有选中内容",2,0);

});

})

jquery.selectall.js

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

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

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值