显示/隐藏 <select> 下拉列表,使用 jQuery,基于值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4282537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:59:18  来源:igfitidea点击:

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

jqueryselectdrop-down-menuoptionshow-hide

提问by iamchriswick

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/

您可以在http://jsfiddle.net/prodac/stAAm/查看我的代码

采纳答案by austinbv

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

使用 jquery:selected一点点文档在这里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.

如果你能给我更多关于你想做的事情的信息,我现在正在更新你的 Jfiddle。



Edit

编辑

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

这是您的答案的更新 jfiddle。 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();
        } });