2011-08-08 17 views
1

私のasp.net Webサイトでは、ネストされたリピータを使用しています。アウトリピータは製品のリストを表示するために使用され、インナーリピータは製品に付随するオプションを表示するために使用されます。これらのリピータは、上記のHTMLではセル内で選択されたチェックボックスに基づいて行にアクセスする

<table class= “productslist”> 
<tbody> 
<tr>....</tr> 
<tr>....</tr> 
<tr class=”productTextAlign”> ......</tr> 
<tr class=”additionalOptions”> ..... </tr> 
<tr class=”additionalOptions”>.....</tr> 

<tr class=”additionalOptions”>.....</tr> 

<tr class=”additionalOptions”>.....</tr> 

<tr class=”additionalOptions”>.....</tr> 
<tr>...</tr> 

<tr class=”productTextAlign”></tr> 

<tr class=”additionalOptions”>.....</tr> 

<tr class=”additionalOptions”>.....</tr> 

<tr class=”additionalOptions”>.....</tr> 

<tr class=”additionalOptions”>.....</tr> 
</tbody> 
</table> 

を以下のようにレンダリングされている 、クラスのproductTextAlign 'はそれぞれTRは「クラスでこの

<td> 
<input type=”checkbox” id =”ProductRepeater_productCheckBox_0”......> 
</td> 
<td class=”numberRequired”> 
<input type=”text” id=”ProductRepeater_numberRequired_0”......> 
</td> 

と各TRのようにレンダリングされているチェックボックスとテキストボックスを持っていますadditionalOptions 'には、これと同様のレンダリングされたチェックボックスがあります。 (クラスのProductTextAlign 'がTRである)に関連する製品のチェックボックスがチェックされている場合、私はチェックしたいと思いますし、その場合、私は使用してアラートをスローしたいと思いません、このチェックボックスをクリックするだけで

<input type=”checkbox” id =”OptionsRepeater_optionCheckBox_0” onclick=”ConfirmProductChosen(this)"......> 

jquery/javascript関数です。

しかし、チェックボックスがチェックされている行にアクセスする方法がわからず、この行の上のどこかの行( '.ProductTextAlign')のチェックボックスにアクセスできます。

誰か助けてくれますか?

答えて

0
// bind the click event to checkboxes within .additionalOptions 
$(".additionalOptions input:checkbox").click(function() { 

    // find the closest .additionalOptions tr and then find the closest previous sibling 
    // with the .productTextAlign class, then find the checkbox within 
    var $checkbox = $(this).closest(".additionalOptions").prevAll(".productTextAlign").find("input:checkbox"); 

    // if the checkbox is checked, fire the alert 
    if (!$checkbox.is(":checked")) 
     alert("Totally checked"); 
} 
0

この

function ConfirmProductChosen(chkBox){ 

    var productTr = $(chkBox).closest("tr").prevAll(".productTextAlign"); 

    if(productTr.find("input[*=productCheckBox]:checked").length){ 
    alert("It is checked"); 
    } 

} 
をお試しください
関連する問題