jQuery show/hide a div based on select value

后端 未结 7 815
走了就别回头了
走了就别回头了 2020-12-10 13:02

I have a select list with values \'all\' and \'custom\'. On select with value \'custom\' a div with class \'resources\' should appear, and if the value is \'all\' it should

7条回答
  •  伪装坚强ぢ
    2020-12-10 13:40

    You can clean up the HTML by dropping the onClick and removing the IDs from the options.

    HTML:

    resources

    And your JavaScript could simply do this:

    $('#privileges').on('change', function() {
            if($(this).val() === 'all') {
                $('.resources').hide();
            } else {
                $('.resources').show();
            }
     });
    

提交回复
热议问题