如何使特定选项从组合框中消失?

How do I make a particular option disappear from a combobox?

本文关键字:消失 组合 何使特 选项      更新时间:2023-09-26

所以我有一个组合框在我的页面有一个广泛的选择选项。当用户选择一个选项并单击一个按钮时,该选项将从该选项下的表中消失。

但是你看,我不能让选项在组合框中消失。我尝试使用。hide(),但选项仍然存在,如果你使用你的箭头,你仍然可以找到它。以下是我目前得到的结果:

$(document).ready(function(){       
    $("#combo").load("/intl/servlet/apps.gpa.HTMLGPA?p1=all_dropdown",function(){
        $("#button").html("<input type='"button'" value='"Filter'">");
    });
    $("#bigTable ").load("/intl/servlet/apps.gpa.HTMLGPA?p1=bigTable");
    $("#button").click(function(){
        var currentSelection = $("#select").val();
        $("#bigTable table tbody tr").each(function( index) {
            var str = $(this).text().trim();    
            if(str.substring(0, 4).trim()==currentSelection ){
                $(this).hide()
            }   
        })
        $("#combo select option").each(function( index) {                   
            if($(this).val()==currentSelection ){
                $(this).hide()
            }   
        })
    });
});

正如您所看到的,最后一段代码是对组合框进行隐藏:

$("#combo select option").each(function( index) {                   
            if($(this).val()==currentSelection ){
                $(this).hide()
            }   
        })

无论如何,我可以使选项完全消失,而不是通过键盘访问?

use 
$("#combo select option").each(function( index) {                   
            if($(this).val()==currentSelection ){
                $(this).remove()
            }   
        })