欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery復(fù)選框全選/取消示例

 更新時(shí)間:2013年12月30日 15:51:27   作者:  
jquery復(fù)選框全選/取消示例,實(shí)現(xiàn)點(diǎn)擊復(fù)選框的時(shí)候全選所有的子復(fù)選框,再點(diǎn)擊取消所有復(fù)選框的選中狀態(tài)

功能:

a:實(shí)現(xiàn)點(diǎn)擊復(fù)選框的時(shí)候全選所有的子復(fù)選框,再點(diǎn)擊取消所有復(fù)選框的選中狀態(tài)

b:有一個(gè)子復(fù)選框選中則父復(fù)選框選中 所有子復(fù)選框都不選中則父復(fù)選框不選中

復(fù)制代碼 代碼如下:

/**
 * 全選函數(shù)
 * @param mainId 主復(fù)選框id
 * @param klass 下屬復(fù)選框的class
 */
function selectAll(mainId,klass){
 $("." + klass).each(function(){
     if($("#" + mainId).attr("checked")== "checked"){
      $(this).attr("checked", "checked");
     }
     else{
      $(this).removeAttr("checked");
     }
 });
}

以上實(shí)現(xiàn)全選及全部取消 所有子復(fù)選框,至于數(shù)據(jù)的實(shí)現(xiàn)則在控制器里接收到復(fù)選框的數(shù)組即可

復(fù)制代碼 代碼如下:

/**
 * 子復(fù)選框有一個(gè)選中 父復(fù)選框就選中 <br>子復(fù)選框全不選 父復(fù)選框不選中
 * @param father 父復(fù)選框的id
 * @param son 子復(fù)選框的class
 */
function checkSonCheckBox(father,son){
 $("."+son).click(function(){
  if($(this).attr("checked")== "checked"){
   $(this).addClass("checked");
  }else{
   $(this).removeClass("checked");
  }
  if($("."+son).hasClass("checked")){
   $("#"+father).attr("checked","checked");
//   console.log("至少有一個(gè)子復(fù)選框選中!");
  }else{
   $("#"+father).removeAttr("checked");
//   console.log("所有子復(fù)選框都未選中!");
  }
 });
};

以上實(shí)現(xiàn) 一個(gè)子復(fù)選框選中則父復(fù)選框選中 所有子復(fù)選框都不選中則父復(fù)選框不選中

相關(guān)文章

最新評(píng)論