2017-08-24 66 views
0

我是新的JavaScript/Jquery和php.I顯示在php中的表的內容。當我選擇一個複選框時,我調用了函數更改。現在我必須禁用除選中的複選框之外的所有複選框。什麼參數應該通過改變函數?我需要做什麼在改變函數,以便我可以得到期望的輸出?如何啓用或禁用表的列的複選框

<div class = "auto_hi_wid " style = "margin-left:10px" id = "generate_shipment"> 
<table border = '2' style="width:100%"> 
      <thead> 

      <tr class = "odd"> 

      <th scope = "col" abbr ="RouteName"width = "0%">RouteName</th> 

      <th scope = "col" abbr ="StartLocation"width = "60%">StartLocation</th> 

      <th scope = "col" abbr ="EndLocation"width = "20%">EndLocation</th> 

      <th scope = "col" abbr ="StartTime"width = "10%">StartTime</th> 

      <th scope = "col" abbr ="EndTime"width = "10%">EndTime</th> 

      <th scope = "col" abbr ="SelectBox"width = "10%">SelectBox</th> 

      </tr> 

      </thead> 

    </table> 
<?php 

    if (sizeof($bookmarked_route) == 0) { 

     echo '<br><div style="text-align:center;font-size:200%;">No Results </div>'; 
     } 
    else { 
      $start_time = "00:00"; 

      echo "<table>\n"; 
      foreach ($bookmarked_route as $route) { 
        $route1 = json_decode($route['route_info'], true); 

        if (isset($route['route_name'])) { 
         echo "<tr>\n". 

         "<td>{$route['route_name']}</td>\n". 

         "<td>{$route1['start_location']}</td>\n". 

         "<td>{$route1['end_location']}</td>\n". 

         "<td>{$start_time}</td>\n". 

         "<td>{$route1['vehicle_engine_time_in_sec']} 
         </td>\n". 

         "<td><input type=\"checkbox\" name=\"checkbox\" 


value=\"\"id=\"checkbox_{$route['route_name']}\"onclick=\"change()\"></td></tr>"; 
        } 
      } 
     echo "</table>"; 
    } 
    ?> 
</div> 

function change(){} 

回答

0

這裏是使用jquery的解決方案。我使用課堂來處理它。試試這個

<?php 

    if (sizeof($bookmarked_route) == 0) { 

     echo '<br><div style="text-align:center;font-size:200%;">No Results </div>'; 
     } 
    else { 
      $start_time = "00:00"; 

      echo "<table>\n"; 
      foreach ($bookmarked_route as $route) { 
        $route1 = json_decode($route['route_info'], true); 

        if (isset($route['route_name'])) { 
         echo "<tr>\n". 

         "<td>{$route['route_name']}</td>\n". 

         "<td>{$route1['start_location']}</td>\n". 

         "<td>{$route1['end_location']}</td>\n". 

         "<td>{$start_time}</td>\n". 

         "<td>{$route1['vehicle_engine_time_in_sec']} 
         </td>\n". 

         "<td><input type=\"checkbox\" name=\"checkbox\" 


value=\"\"id=\"checkbox_{$route['route_name']}\" class=\"change_states\"></td></tr>"; 
        } 
      } 
     echo "</table>"; 
    } 
    ?> 

JQuery的:

<script type="text/javascript"> 
$(document).ready(function() { 
    $('.change_states').on("change",function(){ 
     if($(this).prop("checked") == true){ 
     $(".change_states").attr("disabled", true); //disable all check box 
     $(this).removeAttr("disabled");// enable current checkbox 
    } 

    else //Add this part only if you have to enable all checkbox after uncheck cuurent one 
    { 
     $(".change_states").removeAttr("disabled"); 
    } 
    }); 

}); 

</script> 
+0

非常感謝你終於解決 –