2011-06-23 26 views
1

我有一個網格有許多行和兩列。最後一行包含'以上所有'複選框。當選中時,我希望列中的所有其他複選框變爲未選中狀態。當列中的其他複選框中的其中一個被選中時,我希望以上任何一個複選框都不會自動取消選中。這裏就是我有...問題是與第二條本......我是一個小白'以上都沒有'複選框在網格自動取消選中列中的其他複選框,jquery

columnclear : function() { 
    // NoneClear -Columngrid 
    $(':checkbox[name*="ColumnClear"]').click(function() { 
     if (this.checked === true) { 
      var $table = $(this).closest("table"); 
      var col = $(this).closest("tr").children().index($(this).closest("td")); 
      var index = col+1; 
      $table.find("td:nth-child("+index+") input:checkbox") .attr("checked",false); 
      $table.find("tr:last td:nth-child("+index+") input:checkbox").attr("checked", true); 
     } 
    }); 
    $(':checkbox[name*!="ColumnClear"]').click(function() { 
     if (this.checked === true) { 
      var $table = $(this).closest("table"); 
      var col = $(this).closest("tr").children().index($(this).closest("td")); 
      var index = col+1; 
      $table.find("tr:last td:nth-child("+index+") input:checkbox").attr("checked", false); 
     } 
    }); 
} 

一些HTML的:

<table summary="Which of the following products/systems does your company own and/or plan to purchase within the next 12 months? (Please select all that apply for each column)" class="mrQuestionTable" style=""> 
    <tr> 
    <td id="Cell.0.0"></td> 
    <td id="Cell.1.0" class="mrGridQuestionText" 
    <span class="mrQuestionText" style="color: #000000;;font-weight: bold;">Currently own</span> 
    </td> 
    <td id="Cell.2.0" class="mrGridQuestionText" 
    <span class="mrQuestionText" style="color: #000000;;font-weight: bold;">Plan to purchase</span> 
    </td> 
    </tr> 
    <tr> 
    <td id="Cell.0.1" class="mrGridCategoryText" 
    <span class="mrQuestionText" style="">Creative/Design software</span> 
    </td> 
    <td id="Cell.1.1" 
    <div></div> 
    <input type="checkbox" name="_QQ5_Qdesign_Qrating_Cown" id="_Q0_Q0_Q0_C0" class="mrMultiple" style="" value="own"></input> 
    </td> 
    <td id="Cell.2.1" style="text-Align: Center;vertical-align: Middle;border-color: black;border-style: Solid;border-width: 1px;"> 
    <div></div> 
    <input type="checkbox" name="_QQ5_Qdesign_Qrating_Cplan" id="_Q0_Q0_Q0_C1" class="mrMultiple" style="" value="plan"></input> 
    </td> 
    </tr> 
    <tr> 
    <td id="Cell.0.21" class="mrGridCategoryText" 
    <span class="mrQuestionText" style="">None of the above</span> 
    </td> 
    <td id="Cell.1.21" 
    <div></div> 
    <input type="checkbox" name="_QQ5_Qnon__ColumnClear1_Qrating_Cown" id="_Q0_Q20_Q0_C0" class="mrMultiple" style="" value="own"></input> 
    </td> 
    <td id="Cell.2.21" 
    <div></div> 
    <input type="checkbox" name="_QQ5_Qnon__ColumnClear1_Qrating_Cplan" id="_Q0_Q20_Q0_C1" class="mrMultiple" style="" value="plan"></input> 
    </td> 
    </tr> 
    </table> 
+0

對不起,對。 (':checkbox [name *!='ColumnClear']')中添加的第二個事件片斷(命名爲ColumnClear)中的「none of the above」複選框中添加的click(function(){on)變得無法檢查。應該是可檢查的,並且當該列中的另一個框被檢查時,他們應該取消選中。 – adam

+0

所以第一個事件會在上面沒有被檢查的情況下取消選中列中所有非上述複選框。第二個事件應該自動取消選中上面的複選框,當列中的另一個複選框被選中時,它當前沒有。 – adam

回答

2

假設每個複選框是它自己的表格和「全部清除」複選框有name="ColumnClear",第二個塊應該是:

$(':checkbox[name*!="ColumnClear"]').click(function() { 
    if (this.checked === true) { 
     var $table = $(this).closest("table").find(':checkbox[name*="ColumnClear"]').attr("checked", false); 
    } 
}); 
+0

這似乎不適用於我...所有複選框都在一個大表中 – adam

+0

您可以發佈您的HTML? –

+0

在上面的問題中增加了一些內容 – adam

相關問題