代码之家  ›  专栏  ›  技术社区  ›  Arnkrishn

jQuery从下拉列表中删除选项,给定选项的文本/值

  •  61
  • Arnkrishn  · 技术社区  · 16 年前

    我试着搜索它,但我得到的只是一些例子,其中下拉列表中的整个选项集都被删除了,这不是我所要寻找的。

    4 回复  |  直到 16 年前
        1
  •  165
  •   Yaakov Shoham    16 年前

    $("option[value='foo']").remove();

    或者更好(如果您在页面中选择较少):

    $("#select_id option[value='foo']").remove();

        2
  •  24
  •   E Ciotti    13 年前

    本地化下拉列表元素后

    dropdownElement = $("#dropdownElement");
    

    <option> 元素使用JQuery attribute selector

    dropdownElement.find('option[value=foo]').remove();
    
        3
  •  4
  •   Raj Kumar    8 年前
    $('#id option').remove();
    

    $("#id option:selected").remove();

        4
  •  1
  •   Mahmood    8 年前

    <select id="type" name="type" >
        <option value="Permanent" id="permanent">I am here to stay.</option>
        <option value="toremove" id="toremove">Remove me!</option>
        <option value="Other" id="other">Other</option>
    </select>
    

    $('#toremove').hide();
    
        5
  •  0
  •   Pawprint    5 年前

    我使用了上述选项。从2个下拉框中隐藏条目(首先选择城市,然后选择该城市内的区域)。它在屏幕上工作正常,但隐藏选项仍然可以通过键盘输入选择。

        6
  •  0
  •   Ashish Maurya    5 年前

    以下是代码片段: $(this.find('option[value=yourvalue]);

        7
  •  -1
  •   Vicky    6 年前

    首先查找特定select的类名。

    $('#id').val('');
    $('#selectoptionclassname').selectpicker('refresh');