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