Show/Hide <select> dropdown, with jQuery, based on value

不羁岁月 提交于 2019-11-30 03:22:56

问题


I'm trying to build a custom dropdownlist wich show/hide a second set of dropdowns based on it's selection.

I was wondering if anyone here might be able to help with a solution to this.

You can view my code at http://jsfiddle.net/prodac/stAAm/


回答1:


use the jquery :selected a little bit of documentation is here http://api.jquery.com/selected-selector/

That works in an option select menu

I am updating your Jfiddle now if you can give me a little more info about what you want done.


Edit

Here is an updated jfiddle with your answer. http://jsfiddle.net/stAAm/7/

and a copy of the code for Stack overflow

$('#source').change(function () {
        if ($('#source option:selected').text() == "France"){
            $('.cities').hide();
            $('#source2a').show();
        } else if ($('#source option:selected').text() == "Germany"){
            $('.cities').hide();
            $('#source2b').show();
        } else if ($('#source option:selected').text() == "India"){
            $('.cities').hide();
            $('#source2c').show();
        } else {
            $('.cities').hide();
        } }); 


来源:https://stackoverflow.com/questions/4282537/show-hide-select-dropdown-with-jquery-based-on-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!