如何获得中继器中复选框的唯一ID?

编程入门 行业动态 更新时间:2024-10-19 03:27:06
本文介绍了如何获得中继器中复选框的唯一ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的中继器在用户控件中,并使用asp:repeater.这是我的代码:

My repeater is in a user control and uses an asp:repeater. Here is my code:

<asp:Repeater ID="rptrNotOnFile" Runat="server"> <ItemTemplate> <tr> <td>&nbsp;</td> <td>Item <asp:Label ID="NotOnFileItemNumber" Runat="server" />: <asp:Label ID="lblPartNumberNotOnFile" Runat="server" /> </td> <td> <asp:Checkbox id="chkPartSelected" runat="server" onClick="isSamChecked()"/> </td> <td> <asp:Checkbox id="chkPartWatchParts" runat="server"/> </td> <td> <asp:Checkbox id="samSelected" runat="server" onClick="isMbChecked()"/> </td> </tr> </ItemTemplate> </asp:Repeater>

每个转发器项中都有chkPartSelected和samSelected复选框,我试图取消选中其中一个,反之亦然.

The checkboxes chkPartSelected and samSelected are in each repeater item and I am trying to uncheck one when the other is checked and vice versa.

这是我的jquery函数:

Here's my jquery functions:

<script> function isMbChecked() { if ($('#ResultsNotOnFile_rptrNotOnFile_ctl01_chkPartSelected').is(":checked")) ($('#ResultsNotOnFile_rptrNotOnFile_ctl01_chkPartSelected').prop("checked", false)) } function isSamChecked() { if ($('#ResultsNotOnFile_rptrNotOnFile_ctl01_samSelected').is(":checked")) ($('#ResultsNotOnFile_rptrNotOnFile_ctl01_samSelected').prop("checked", false)) } </script>

当我对中继器中每个复选框的唯一ID进行硬编码时,这些函数起作用,但是我不希望对其进行硬编码,因为我可以拥有一个或多个中继器项目.

These function work when I hard code the unique id for each checkbox in the repeater, but I do not want it hardcoded because I can have one or many repeater items.

如何获取唯一的ID并将其传递给函数?

How do I get that unique id and pass it to the functions?

感谢您的帮助

JGraham

推荐答案

如果我是你,我会放弃ID,因为它们不是唯一的,并在其中添加一些类以使其更易于识别.

If I were you, I would just ditched the IDs since they aren't unique, and add some classes to these to make them more identifiable.

例如

<asp:Checkbox runat="server" class="sam" onClick="isSamChecked()"/> <asp:Checkbox runat="server" class="mb" onClick="isMbChecked()"/>

然后您可以做类似的事情

Then you could do something like

<script> function isMbChecked() { var closest = $(this).parent('td').siblings().children('.sam'); closest.prop('checked', !closest.prop('checked')); } function isSamChecked() { var closest = $(this).parent('td').siblings().children('.mb'); closest.prop('checked', !closest.prop('checked')); } </script>

更多推荐

如何获得中继器中复选框的唯一ID?

本文发布于:2023-11-25 01:57:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627844.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得   复选框   器中   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!