Filter Category Select Drop down based on Another drop down option

前端 未结 4 979
盖世英雄少女心
盖世英雄少女心 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 08:11

    This is a simple approach to the issue, which should be rather solid:

    
    
    

    css:

    .hiddenOptions > select
    {
       display: none;
    }
    
    .hiddenOptions > select.active
    {
       display: inline-block;
    }
    

    JS:

    $('.masterSelect').on('change', function() {
        $('.hiddenOptions select').removeClass("active");
        $('.hiddenOptions select').eq($(this).val()).addClass("active");
    
        showValue();
    });
    
    $('.hiddenOptions select').on('change', function() {
        showValue();
    });
    
    $('.masterSelect').trigger('change'); //set initial value on load
    
    function showValue()
    {
        console.log($('.hiddenOptions select.active').val());
    }
    

    https://jsfiddle.net/g5h2k6t4/1/

提交回复
热议问题