在我的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中,每个带有'productTextAlign'类的tr都有一个复选框和文本框,它们都是这样呈现的
<td>
<input type=”checkbox” id =”ProductRepeater_productCheckBox_0”......>
</td>
<td class=”numberRequired”>
<input type=”text” id=”ProductRepeater_numberRequired_0”......>
</td>
并且每个带有'additionalOptions'类的tr都有一个类似于此的复选框。
<input type=”checkbox” id =”OptionsRepeater_optionCheckBox_0” onclick=”ConfirmProductChosen(this)"......>
点击此复选框后,我想检查相关的产品复选框(位于带有'ProductTextAlign'类的tr中)是否已选中,如果不是我想使用jquery / javascript函数抛出警报
但我不知道如何访问选中复选框的行,然后可以访问该行上方某处的行中的复选框(带有'.ProductTextAlign')。
有人可以帮帮我吗?
答案 0 :(得分: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");
}
答案 1 :(得分:0)
试试这个
function ConfirmProductChosen(chkBox){
var productTr = $(chkBox).closest("tr").prevAll(".productTextAlign");
if(productTr.find("input[*=productCheckBox]:checked").length){
alert("It is checked");
}
}