Show/Hide multiple DIVs with Select using jQuery

前端 未结 4 1710
孤城傲影
孤城傲影 2020-12-15 11:49

I essentially have the same situation as the person in the following question:

Link: how to show/hide divs by select.(jquery)

Through extensive searching wit

4条回答
  •  醉酒成梦
    2020-12-15 12:48

    @fudgey has given a nice solution. but have little doubt. It will depend on value and need to change Attribute ID of

    every time.

    So I'd do this `

        $(document).ready(function() {
            $('.box').hide();
            $('#dropdown').change(function() {      
                var selectedIdx = (0 == $(this).attr("selectedIndex"))? '' :                 $(this).attr("selectedIndex");
                if("" != selectedIdx){
                    $('#divarea'+ selectedIdx ).hide().siblings().show();
                } else {
                    $('.box').hide();
                }        
            });
        });
    
    
    DIV Area 1
    DIV Area 2
    DIV Area 3
    `

提交回复
热议问题