繁体   English   中英

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

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

我有一个下拉列表:

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM