JQuery中实现全选反选代码

代码加入<script>标签中,然后在你所要实现的功能,在实现功能按钮处用onclick="return DelSelect()"调用.
 

//实现反选全选

$("#checkall").click(function(){
  $("input[name='id[]']").each(function(){
    if (this.checked) {
       
      this.checked = false;
    }
    else {
      this.checked = true;
    }
  });
})
//删除提示

function DelSelect(){
  var Checkbox=false;
   $("input[name='id[]']").each(function(){
    if (this.checked==true) {   
    Checkbox=true;  
    }
  });
  if (Checkbox){
    var t=confirm("您确认要删除选中的内容吗?");
    if (t==false) return false;     
  }
  else{
    alert("请选择您要删除的内容!");
    return false;
  }
}
<script type="text/javascript">

function del(){
  if(confirm("您确定要删除吗?\n\n请确认!"))
  {
    return true;
  }
  else
  {
    return false;
  }
}

$("#checkall").click(function(){ 
  $("input[name='id[]']").each(function(){
    if (this.checked) {
       
      this.checked = false;
    }
    else {
      this.checked = true;
    }
  });
})

function DelSelect(){
  var Checkbox=false;
   $("input[name='id[]']").each(function(){
    if (this.checked==true) {   
    Checkbox=true;  
    }
  });
  if (Checkbox){
    var t=confirm("您确认要删除选中的内容吗?");
    if (t==false) return false;     
  }
  else{
    alert("请选择您要删除的内容!");
    return false;
  }
}

</script>

猜你喜欢

转载自blog.csdn.net/zhaojie911272507/article/details/81433245