显示/隐藏 <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
Show/Hide <select> dropdown, with jQuery, based on value
提问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 :selected
a 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();
} });