jQuery show/hide drop-down options based on another drop-down option

前端 未结 7 716
离开以前
离开以前 2020-12-20 07:45

I am trying to create a drop-down select menu that will consist of three select boxes, where the 3rd box will show/hide specific option based on an option selected in the 1s

相关标签:
7条回答
  • 2020-12-20 08:35

    Use selectedIndex property to hide show third selection box

        $("#select_1").on('change',function(){
        if($("#select_1").prop("selectedIndex")==1){
            $('#select_3 option').show(); 
            $('#select_3 option:gt(3)').hide(); 
            //$('#select_3 option:lt(3)').show();
        }else if($("#select_1").prop("selectedIndex")==2){
         $('#select_3 option').show(); 
         $('#select_3 option:lt(4)').hide();   
         $('#select_3 option:gt(6)').hide();   
        }else if($("#select_1").prop("selectedIndex")==3){
         $('#select_3 option').show(); 
         $('#select_3 option:lt(7)').hide();   
        }
    });
    

    Demo

    0 讨论(0)
提交回复
热议问题