查找与当前元素相关的文本框
-
05-07-2019 - |
题
这是我的HTML:
<tr>
<td colspan="2" class="borderBottomCell">
<div class="benefitInfo" style="WIDTH: 99%! important;">
<asp:DropDownList runat="server" ID="ddlbc1" />
<asp:Label runat="server" ID="lblbc1" />
<asp:Literal runat="server" ID="spcbc1" Text=" " />
<asp:Label runat="server" ID="bd1" />
<asp:HiddenField runat="server" ID="hdnbc1" />
</div>
</td>
<td class="borderBottomCell2">
<asp:TextBox runat="server" ID="amt1" CssClass="transparentTextBox amount" Width="60px" Columns="9" />
</td>
<td class="borderBottomCell2">
<asp:TextBox runat="server" ID="int1" CssClass="transparentTextBox" Width="60px" Columns="9" />
</td>
</tr>
我正在尝试获取textbox amt1的引用。我在循环中需要它,因为这只是表中的一行。我需要遍历下拉列表,如果selectedIndex大于零(> 0),则文本框的数量需要大于零(> 0)。我将来会实现dataType验证,目前我只需要知道如何使用我的循环访问相关的文本框。
到目前为止我有这个代码......
$(".benefitInfo select").each(function() {
var ddl = $(this);
});
实现这一目标的最佳方法是什么?我应该得到一个参考 parent()。parent()。next()。find(&quot;:input&quot;)
...或者那样的东西可能会吗?
解决方案
这应该有效:
$(".benefitInfo select").each(function() {
var ddl = $(this);
var amtTxt = ddl.closest('tr').find('.amount');
});
不隶属于 StackOverflow