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
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 );
以上所述就是本文的全部内容了,希望大家能够喜欢。