jQuery keep show hide state based on select option

前端 未结 3 1830
梦谈多话
梦谈多话 2021-01-22 01:54

I have drop down select and show hide other fields (within divs) based on option selected in the dropdown list.

This code works fine and show hide based on selection but

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-22 02:39

    Just do the same in document.ready

    $(document).ready(function(){
        $('#row1_col1_layout_type1, #row1_col1_layout_type2, #row1_col1_layout_type3').hide();
        $('#row1_col1_' + $('#row1_layout_options').val()).show();
    
        $('#row1_layout_options').on('change',function() {
           $('#row1_col1_layout_type1, #row1_col1_layout_type2, #row1_col1_layout_type3').hide();
           $('#row1_col1_' + $(this).val()).show();
        });
    });
    

    here is the fiddle

提交回复
热议问题