【问题标题】:How to get drop down list value per selected row?如何获取每个选定行的下拉列表值?
【发布时间】:2013-03-09 17:06:07
【问题描述】:

我有一张看起来像这样的桌子

<table id="grid" class="table table-bordered table-hover table-inline">
    <thead>
        <tr>
            <th>Id</th>
            <th>Dropdown List</th>
            <th><input id="selectAll" type="checkbox" /></th>
        </tr>
    </thead>
    <tbody data-bind="foreach: stuff
        <tr>
            <td data-bind="text: someId"></td>
            <td>
                <select class="input-medium" data-bind="options: someStuff, optionsText:'DisplayName', optionsValue:'StandardCode'"></select>                           
            </td>
            <td>
                <input type="checkbox" data-bind="value: someId"/>
            </td>
        </tr>
    </tbody>
</table>

然后我的 javascript 我正在像这样遍历选定的行

$('grid input[type="checkbox"]:checked').each(function () {

    var someSelectedId= $(this).val();

    var dropDownlistValue= ??       
});

我正在使用敲除将我的数据绑定到表格和下拉列表。

当我遍历行时​​,如何在每行的下拉列表中获取所选值?对于我的生活,我似乎无法弄清楚。谢谢!

【问题讨论】:

    标签: javascript jquery knockout.js


    【解决方案1】:

    用途:

    var dropDownlistValue = $(this).parent().prev().find('select.input-medium').val();
    

    【讨论】:

      【解决方案2】:

      或者……

      $(this).closest("tr").find("select.input-medium").val();
      

      A.V 的方法可能更快,但转到 TR 允许更大的灵活性,因为无论它在行中的哪个位置,它都会找到选择。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-22
        相关资源
        最近更新 更多