从下拉列表中获取过滤后的数据,并显示在另一个下拉列表中

Fetch filtered data from the drop down list and present in another drop down list

本文关键字:下拉列表 显示 另一个 获取 过滤 数据      更新时间:2023-09-26

我有一个下拉列表:

<asp:DropDownList ID="DropDownList1" runat="server" Width="222px">
    <Items>
        <asp:ListItem Text="Option 1" Value="1" />
        <asp:ListItem Text="Option 2" Value="2" />
        <asp:ListItem Text="Option 3" Value="3" />
        <asp:ListItem Text="Option 4" Value="4" />
        <asp:ListItem Text="Option 5" Value="5" />
        <asp:ListItem Text="Option 6" Value="6" />
        <asp:ListItem Text="Option 7" Value="7" />
    </Items>
</asp:DropDownList>

我想创建一个下拉列表,上面提到的下拉列表项的所有项目,除了被选中的(上面)。例如:我在上面的下拉列表中选择了选项4,我想在第二个下拉列表中显示从1到7的选项(选项4除外)。

谁能告诉我如何实现它?

我使用下面的代码将下拉列表的值克隆到其他下拉列表的值。

<script type="text/javascript">
$(function() {
$("#btnclone").click(function() {
$('#DropDownList1').clone().attr('id', 'choices_' + $(this).index()).insertAfter("#DropDownList1");
});
});
</script>

但是谁能建议如何显示所有的值,除了从前面的下拉列表中选择的值?

这个很适合我:

 <script type="text/javascript">
    $('#btnclone').click(function () {
        var original = $('select.selService:eq(0)');
        var allSelects = $('select.selService');
        var clone = original.clone();
        $('option', clone).filter(function (i) {
            return allSelects.find('option:selected[value="' + $(this).val() + '"]').length;
        }).remove();
        $('#target').append(clone).append('<br />');
    });
</script>