2017-02-03 64 views
1
<table class="table borderless"> 
    <thead> 
     <tr> 
     <th>Rank</th> 
     <th>+/-</th> 
     <th>Searches</th> 
     <th></th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <td><input type="radio" name="optradio" class="custom"> ALL</td> 
     <td><input type="radio" name="optradio" class="custom"> ALL</td> 
     <td><input type="radio" name="optradio" class="custom"> ALL</td> 
     <td><input id="ex2" type="text" class="span2" value="" data-slider-min="10" data-slider-max="1000" data-slider-step="1" data-slider-value="[0,1000]" data-slider-id="RC" id="R"/></td> 
     </tr> 
     <tr> 
     <td><input type="checkbox" class="custom-selector"> Rank 1-10</td> 
     <td><input type="checkbox" > Up</td> 
     <td><input type="checkbox" > Over</td> 
     </tr> 
     <tr> 
     <td><input type="checkbox" class="custom-selector"> Rank 11-20</td> 
     <td><input type="checkbox" > Down</td> 
     <td><input type="checkbox" > Under</td> 
     </tr> 
     <tr> 
     <td><input type="checkbox" class="custom-selector"> Rank 21-100</td> 
     <td><input type="checkbox" > No movement</td> 

     </tr> 
     <tr> 
     <td><input type="checkbox" class="custom-selector"> Not in top 100</td> 

     </tr> 
    </tbody> 
    </table> 

腳本:單選按鈕,檢查所有箱子

$(document).ready(function() { 
     $(".custom").change(function() { 
       $(".custom").parent().find(".custom-selector").prop("checked", true); 
     }) 
    }); 

我需要的是一個單選按鈕被選中時,檢查所有的箱子。

現在沒有任何反應,當我點擊單選按鈕。但是,如果我添加這個單選按鈕:

<input type="radio" id="op5" value="1" name="options2" class="custom"> 

然後他們都工作。即使是最初的一個檢查所有的框。

這是什麼奇怪的行爲?我失去了一些東西

編輯:它看起來單選按鈕必須在表外?我能以某種方式擁有它嗎?

+0

你爲什麼不添加類的表。例如,class =「table borderless ranking」。然後,您可以選擇簡單的$(.stores .custom-selector')checboxes。 – rNix

+0

是不是你去差異類名稱的排名,位置,搜索 –

+0

是有什麼原因你使用單選按鈕選擇所有,我的想法將去複選框.. –

回答

4

嘗試:

$(".custom").closest("tbody").find(".custom-selector").prop("checked", true); 

或剛:

$(".custom-selector").prop("checked", true); 
1

試試這個:

$(".custom").change(function() { 
    $(this).parents('tbody').find(".custom-selector:checked"); 
}); 

和一些參考:https://api.jquery.com/checked-selector

最終刪除你的行動selecto [R使用.not(this)

0

試試這個:

$(document).ready(function() { 
      $(".custom").change(function() { 
      $(".custom-selector").prop("checked", true); 
     }) 
    });