doubi8965 2014-07-01 10:15
浏览 89
已采纳

选择所有复选框不起作用

I have to display zone names and the regions coming under the respective zone. I have checkboxes on the right side of each zone and also on the side of regions for selecting the zones and areas. When I check a particular zone,I need to check all the regions coming under that particular zone only. I am displaying the zone data and corresponding areas from the database.

My php code is like this:

//displaying zone name

 <table cellpadding="15" cellspacing="10">
 <?php
 $last_route = '';  
 $getbus = mssql_query("SELECT brd.BusrouteID,BusRoute,brd.AreaID,br.BusRoute,a.AreaName_1 FROM dbo.Acc_BusRouteDetail brd JOIN dbo.PRTL_BusRoute br ON br.busrouteid = brd.busrouteid JOIN dbo.GEN_Area a ON a.areaid = brd.areaid ORDER BY br.busroute, a.areaname_1");
 while($data_getbus = mssql_fetch_array($getbus)){ 
   if($last_route != $data_getbus['BusRoute']) { 
       $last_route = $data_getbus['BusRoute'];//last_route contain zone names
       echo '<tr><td><label for="'.$data_getbus[BusrouteID].'"><h4>'.$last_route.'</h4>  </label></td><td><input type="checkbox" class="zone_check" id="'.$data_getbus[BusrouteID].'" name="zone[]" value="'.$data_getbus[BusrouteID].'"></td></tr><tr>';
     }
      echo '<td><label for="'.$data_getbus[BusrouteID]."_".$data_getbus[AreaID].'">'.$data_getbus['AreaName_1'].'</label></td>
     <td><input type="checkbox" id="'.$data_getbus[BusrouteID]."_".$data_getbus[AreaID].'" name="arealist[]" value="'.$data_getbus[BusrouteID]."_".$data_getbus[AreaID].'"  >'."</td></tr>";
  } 

?>
 </table>

My Jquery is like this:

$(".zone_check").change(function(){
          var checkboxes = $(this).children().find(':checkbox');
          if($(this).prop('checked')) {
          checkboxes.prop('checked', true);
        } else {
          checkboxes.prop('checked', false);
        }
    });

screen shot

  • 写回答

2条回答 默认 最新

  • drau67562 2014-07-01 10:29
    关注

    Looks like you are targeting the checkboxes in the next row, so try

    $(".zone_check").change(function () {
        $(this).closest('tr').next().find(':checkbox').prop('checked', this.checked);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类