你的位置:首页 > Java教程

[Java教程]js checkBox的全选,反选,与赋值


//js 数值是否在数组中Array.prototype.in_array = function(e){   for(i=0;i<this.length;i++){     if(this[i] == e)       return true;   }   return false; } //js数组indexArray.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);  }})//单选增加idfunction 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);  }}