Drop down list - display div when clicking an option

前端 未结 2 1316
小鲜肉
小鲜肉 2020-12-21 11:47

You must write a function that \'shows\' the corresponding part of the form depending on what the user has selected. For example, if \'Pizza\' is selected, the div #section2

2条回答
  •  时光说笑
    2020-12-21 12:31

    DEMO: http://jsfiddle.net/iambriansreed/rQr6v/

    JavaScript:

    var sections = {
        'pizza': 'section2',
        'mex': 'section3',
        'thai': 'section4'   
    };
    
    var selection = function(select) {
    
        for(i in sections)
            document.getElementById(sections[i]).style.display = "none";    
    
        document.getElementById(sections[select.value]).style.display = "block";
    
    }
    

    Checkout the demo. Replace the section3 and section4 divs with actual content.

提交回复
热议问题