jQuery remove options from select

后端 未结 8 836
一生所求
一生所求 2020-11-28 02:58

I have a page with 5 selects that all have a class name \'ct\'. I need to remove the option with a value of \'X\' from each select while running an onclick event. My code is

相关标签:
8条回答
  • 2020-11-28 03:44

    It works on either option tag or text field:

    $("#idname option[value='option1']").remove();
    
    0 讨论(0)
  • 2020-11-28 03:47
    $('.ct option').each(function() {
        if ( $(this).val() == 'X' ) {
            $(this).remove();
        }
    });
    

    Or just

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

    Main point is that find takes a selector string, by feeding it x you are looking for elements named x.

    0 讨论(0)
提交回复
热议问题