日期:2014-05-16  浏览次数:20336 次

关于checkbox全选功能和选择器有关的问题
这是html代码 ,不止一个部门,是根据json数据显示的
<div class="onePart"><!--为了使全选好定位-->
   <a href="#" id="selectAll1" class="selectAll" >全选</a>
   <a href="#" id="cancelAll1" class="cancelAll" >取消</a>
 <div data-role="collapsible" data-theme="b" id="depart1">
<h1>销售部</h1>
<input type="checkbox" id="stf0" name="stf0" value="0" />
<label for="stf0">主管1</label>
<input type="checkbox" id="stf1" name="stf1" value="1"/>
<label for="stf1">员工1</label>
<input type="checkbox" id="stf2" name="stf2" value="2"/>
<label for="stf2">员工2</label>
<input type="checkbox" id="stf3" name="stf3" value="3"/>
<label for="stf3">员工3</label>
</div>
</div>

这是js,之所以要用这样的方法,是因为上面的HTML是根据json动态添加的,可能还有selectAll2,selectAll3

        function selectE(json){
  for(var i=0;i<json.length;i++){
var s="#selectAll"+(i+1);
    $(s).bind("click",function(e){
  var id=e.target.id.toString();
  var j=id.length-1;
  var c=id.charAt(j);
  var d="#depart"+c+":checkbox";  
  alert(d);//这个结果是点击selectAll1就显示#depart1:checkbox,点击selectAll2就显示#depart2:checkbox
        $(d).attr("checked",true).checkboxradio("refresh");  
});
  }
}//selectE


但是为什么点击全选后下面的checkbox不刷新啊。。
checkbox json 选择器

------解决方案--------------------
 var d="#depart"+c+" :checkbox"; 
#depart1 :checkbox 加个空格表示子选择
#depart1:checkbox 表示id为#depart1的checkbox当然找不到