How to hide html form select option?

后端 未结 4 1062
萌比男神i
萌比男神i 2021-01-24 01:43

I have a very simple form which I would like to hide select options when another select field refines it.

Currently I have tried dispay: none as an inline s

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-24 02:05

    I think the easier way to accomplish what you have in mind is to have three different dropdown lists in place of the second dropdown. Then, the first drop down can choose which one of those to show based on it's value.

    Much simpler.

    With that change, you can make your callback simply:

    $('#refine').change(function () {
        var refine = $('option:selected', this).val().replace(/ /g, "-");
    
        $('.refined').removeClass('hidden').addClass('hidden');
        $('#'+refine).removeClass('hidden').removeAttr('disabled');
    });
    

    Edit: I forked your fiddle (and maybe edited your original?). It has the changes I suggested.

提交回复
热议问题