首页 > Web开发 > 详细

js checkBox的全选,反选,与赋值

时间:2015-03-12 00:40:56      阅读:268      评论:0      收藏:0      [点我收藏+]
//js 数值是否在数组中
Array.prototype.in_array = function(e){ 
  for(i=0;i<this.length;i++){ 
    if(this[i] == e) 
      return true; 
  } 
  return false; 
} 
//js数组index
Array.prototype.find_str=function(string){
  var str = this.join(""); 
  return str.indexOf(string); 
}

var houseIds=new Array();
$("#chebox-list-all").click(function(){
  if($("#chebox-list-all").attr("checked")){
    $("[name=‘checkboxes‘]").attr("checked",‘true‘);//全选 增加id
    var ids = document.getElementsByName(‘checkboxes‘);
    var value = new Array();
    for(var i = 0; i < ids.length; i++){
      if(ids[i].checked)
      houseIds.push(ids[i].value);
    } 
  alert(houseIds);
  }else{
    $("[name=‘checkboxes‘]").removeAttr("checked");//反选 删除Ids
    houseIds=[];
    alert(houseIds);
  }
})
//单选增加id
function check(obj){
  if(!houseIds.in_array(obj.value)){
    houseIds.push(obj.value);
    alert(houseIds);
  }else{
    var index=houseIds.find_str(obj.value);
    houseIds.splice(index, 1)
    alert(houseIds);
  }
}

  

js checkBox的全选,反选,与赋值

原文:http://www.cnblogs.com/EnjoyMore/p/4331297.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!