【问题标题】:Find textbox relevant to current element查找与当前元素相关的文本框
【发布时间】:2017-01-01 23:36:36
【问题描述】:

这是我的 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="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" />
                            <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>

我正在尝试获取对文本框 amt1 的引用。我需要循环使用它,因为这只是表格中的一行。我需要遍历下拉列表,如果 selectedIndex 大于零( > 0 ),金额文本框的金额必须大于零( > 0 )。我将在未来实现数据类型验证,目前我只需要知道如何通过我的循环访问相关的文本框。

到目前为止我有这个代码......

$(".benefitInfo select").each(function() {
    var ddl = $(this);

});

实现这一目标的最佳方法是什么?我是否应该获得parent().parent().next().find(":input") 的参考...或者类似的东西?

【问题讨论】:

    标签: javascript jquery html html-table


    【解决方案1】:

    这应该可行:

    $(".benefitInfo select").each(function() {
        var ddl = $(this);
        var amtTxt = ddl.closest('tr').find('.amount');
    });
    

    【讨论】:

    • 我会提出一个额外的建议,并使用元素类型来限定 CSS 类,即div.benefitInfoinput.amount
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 2016-04-25
    • 2011-06-02
    相关资源
    最近更新 更多