2011-08-08 69 views
1

在我的asp.net網站中,我使用嵌套中繼器。外部中繼器用於顯示產品列表,內部中繼器用於顯示產品附加選項。 這些中繼器呈現爲以下基於其中一個單元格中選中的複選框訪問行

<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> 

在上面的HTML,與類中的每個TR「productTextAlign」已經得到了複選框,文本框,其呈現這樣

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

並與類中的每個TR' additionalOptions'有一個類似於這個的複選框。

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

在此複選框上的點擊,我想檢查是否有相關產品複選框(這與類的ProductTextAlign'的TR)被選中,如果沒有,我想用一個扔一個警告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"); 
    } 

} 
相關問題