jQuery - 几个选择菜单选项使字段显示/隐藏
我尝试寻找这样的帖子,但尽管许多帖子相似,但没有一个能够正确解决我的问题。
这是我的情况:
我有两个选择菜单,国家和州,一个在另一个的顶部。它们的默认值为“-Select-”。
如果用户选择除美国或加拿大以外的其他国家/地区,则州选择菜单应隐藏,并且应显示常规文本字段(请参阅 HTML结构如下)。如果在选择美国或加拿大后,用户决定选择任何其他国家/地区,则刚刚出现的文本框应再次隐藏,并且国家/地区的选择菜单 应该会重新出现。
最后,如果用户首先选择美国或加拿大,则不会发生任何事情,州选择保持可见。
如果您能在这方面给我任何帮助,我将不胜感激。
**
这是基本的 HTML:
国家选择:
<select name="country">
<option value="null" selected="selected">—Select—</option>
<option value="United States">United States</option>
<option value="Canada">Canada</option>
<option value="null" >-----------------------------------------</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
...
</select>
州选择& 输入:
<select name="state">
<option value="null" selected="selected">—Select—</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
...
</select>
<br>
<input name="textfield" type="text" id="textfield" class="country-textbox">
更新 6/14: sAc 的解决方案运行良好。然而,我只是想到了其他事情:
我还决定为加拿大各省添加另一个选择菜单(doh!),所以现在:
当选择加拿大时,美国 选择,文本字段应隐藏,加拿大 选择应可见。
当选择美国时,加拿大选择和文本字段应隐藏,而美国选择应可见。
如果选择任何其他值,则应隐藏美国和加拿大选择,并且文本字段可见。
感谢一百万您的帮助。
更新 6/15: 好吧,扩展版本没有额外的帮助。无论如何谢谢大家。
I tried looking for posts like this one but although many are similar, none address my problem properly.
Here's my situation:
I have two select menus, Country and State, one of top of the other. Their default values are "-Select-".
If the user selects another country different than United States or Canada, the State select menu should hide and a regular text field should show (see HTML structure below). If, after selecting United States or Canada the user decides to select any other country, then the text box that just appeared should hide again and the select menu for State should reappear.
Last, if the user selects United States or Canada at first, nothing happens, the State select stays visible.
Any help you can give me with this, it's greatly appreciated.
**
This is the basic HTML for this:
Country's select:
<select name="country">
<option value="null" selected="selected">—Select—</option>
<option value="United States">United States</option>
<option value="Canada">Canada</option>
<option value="null" >-----------------------------------------</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
...
</select>
State's select & input:
<select name="state">
<option value="null" selected="selected">—Select—</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
...
</select>
<br>
<input name="textfield" type="text" id="textfield" class="country-textbox">
UPDATE 6/14: sAc's solution worked perfectly. However, I just thought of something else:
I also decided to include another select menu for the Canadian Provinces (doh!), so now:
When Canada is selected, the United States select and the text field should be hidden, and the Canada select should be visible.
When United States is selected, the Canada select and the text field should be hidden, and the United States select should be visible.
If any other value is selected, the United States and Canada selects should be hidden and the text field visible.
Thanks a million for your help.
UPDATE 6/15: Well, no additional help for the extended version. Thanks anyway everyone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
怎么样:
How about:
jQuery!
jQuery!
和
AND