【问题标题】:How do I select the next "select" (dropdown) in this HTML?如何在此 HTML 中选择下一个“选择”(下拉菜单)?
【发布时间】:2012-01-31 16:00:26
【问题描述】:

我的html是:

    <tr>
        <td><select id = "delAppSelectApp" name="delAppSelectApp"><option value="--Select--"> --Select--</option></select></td>
        <td><select id = "delAppSelectAppVers" name="delAppSelectAppVers"><option value="--Select--">--Select--</option></select></td>
        <td><input type="submit" name="submitDelAppVers" id="submitDelAppVers" value="Delete Application Version" /></td>
    </tr>

我的脚本是:

$(document).ready(function(){
    $("#delAppSelectApp").change(function(){
        alert( $(this).nextAll("select").attr("id") );
    });
});

我希望窗口提醒“delAppSelectAppVers”,但没有发生。我究竟做错了什么 ?我什至尝试过“兄弟姐妹”功能。

【问题讨论】:

    标签: javascript jquery select next


    【解决方案1】:
    $(document).ready(function() {
        $("#delAppSelectApp").change(function() {
            alert( $(this).closest("td").next().find('select').attr("id") );
        });
    });
    

    这是一个演示:http://jsfiddle.net/7twmJ/

    【讨论】:

      【解决方案2】:

      它不起作用,因为在节点 xpath/axis 的同一级别上没有“下一个”元素(兄弟)。试试这个:

      $(this).parent.next().children("select:first").attr("id")
      

      【讨论】:

        猜你喜欢
        • 2011-03-08
        • 2017-04-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-20
        • 2011-05-14
        相关资源
        最近更新 更多