Want to show/hide div based on dropdown box selection

后端 未结 7 2137
感情败类
感情败类 2020-12-08 01:10

I want to have jQuery show div id=\'business\' only if \'business use\' is selected in the dropdown box.

This is my code:



        
7条回答
  •  醉梦人生
    2020-12-08 01:37

    https://www.tutorialrepublic.com/codelab.php?topic=faq&file=jquery-show-hide-div-using-select-box It's working well in my case

    $(document).ready(function(){
        $("select").change(function(){
            $(this).find("option:selected").each(function(){
                var optionValue = $(this).attr("value");
                if(optionValue){
                    $(".box").not("." + optionValue).hide();
                    $("." + optionValue).show();
                } else{
                    $(".box").hide();
                }
            });
        }).change();
    });
    
    
    
    
    jQuery Show Hide Elements Using Select Box
    
    
    
    
    
        
    You have selected red option so i am here
    You have selected green option so i am here
    You have selected blue option so i am here

提交回复
热议问题