码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-03-12 00:41:22      阅读:131      评论: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)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!