Filter Category Select Drop down based on Another drop down option

前端 未结 4 1016
盖世英雄少女心
盖世英雄少女心 2021-01-05 07:54

I want to filter the list of options based on the selection of another drop down.

Please see the jquery code below; i am sure there is a tiny bit that i am missing t

4条回答
  •  醉话见心
    2021-01-05 07:59

    You could do it this way:

    $(document).ready(function () {
        $('#selectcat').change(function () {
            $('#selectprod option').show();
            if ($('option:selected', this).attr('id') == 'selectionone') {
                $('#selectprod option.edibles').hide();
            }
            if ($('option:selected', this).attr('id') == 'selectiontwo') {
                $('#selectprod option.vegfats').hide();
            }
        });
    });
    

    jsFiddle example

    As this may not work in older versions of IE, you can replace $('#selectprod option').show(); with $('#selectprod option').prop('disabled',false); and $('#selectprod option.vegfats').hide(); with $('#selectprod option.vegfats').prop('disabled',true);

提交回复
热议问题