根据在其单元格中选定的复选框访问行

发布于 2024-11-28 18:19:21 字数 1541 浏览 1 评论 0原文

在我的 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”)中的复选框。

有人可以帮我解决这个问题吗?

In my asp.net website I am using nested repeaters.Outer repeater is used to display a list of products and inner repeater is used to display additional options accompanying the products.
These repeaters are rendered as following

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

In the HTML above, each tr with class 'productTextAlign' has got a checkbox and textbox which are rendered like this

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

and each tr with class 'additionalOptions' has a checkbox rendered similar to this.

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

On the click of this checkbox I would like to check if the associated Product checkbox(which is in the tr with class 'ProductTextAlign') is checked and if its not I would like to throw an alert using a jquery/javascript function.

But I am not sure how to access the row in which the checkbox is checked and in turn get access to the checkbox in the row(with '.ProductTextAlign') somewhere above this row.

Could someone please help me with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蹲在坟头点根烟 2024-12-05 18:19:21
// 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");
}
// 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");
}
财迷小姐 2024-12-05 18:19:21

试试这个

function ConfirmProductChosen(chkBox){

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

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

}

Try this

function ConfirmProductChosen(chkBox){

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

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文