【发布时间】:2013-10-22 05:41:59
【问题描述】:
我想根据用户从两个下拉列表中的选择显示一个 div。
虽然我将向用户显示 3 个下拉选项,但我只会根据前两个的选择生成输出:
这意味着我将根据用户的选择总共有 9 个可能的输出:
- 海滩 --> 寒冷
- 海滩 --> 快节奏
- 海滩 --> 两者都有
- 博物馆 --> 寒意
- 博物馆 --> 快节奏
- 博物馆 --> 两者
- 山 --> 寒冷
- 山脉 --> 快节奏
- 山 --> 两者
仅作类似参考,几个月前,我used 使用以下脚本根据 2 个下拉选择生成特定输出: http://jsfiddle.net/barmar/ys3GS/2/
<body>
<h2>Find your Animal Name</h2>
<p>Select your birth month and your favorite color and find your animal name.</p>
<form>
<select id="month">
<option value="">- birth month -</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<label class="January" for="January">January Name</label>
<label class="February" for="February">February Name</label>
<label class="March" for="March">March Name</label>
<label class="April" for="April">April Name</label>
<label class="May" for="May">May Name</label>
<label class="June" for="June">June Name</label>
<label class="July" for="July">July Name</label>
<label class="August" for="August">August Name</label>
<label class="September" for="September">September Name</label>
<label class="October" for="October">October Name</label>
<label class="November" for="November">November Name</label>
<label class="December" for="December">December Name</label>
<select id="color">
<option value="">- favorite color -</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
<option value="Red">Red</option>
</select>
<label class="Green" for="Green">Green Name</label>
<label class="Blue" for="Blue">Blue Name</label>
<label class="Red" for="Red">Red Name</label>
</form>
<p id="output"></p>
</body>
但这种需求有点不同。关于如何实现这一目标的任何想法?换句话说——一旦用户选择了这两个选项,我希望相应的 div(9 个选项中的)显示在下面。
非常感谢!
【问题讨论】:
-
如果您忽略了第三个下拉菜单,那么您现有的脚本有什么问题,它已经适用于两个?
-
我也想问同样的问题。我认为您需要澄清您想要的不同之处(除了添加另一个您不会用于此输出的下拉列表)。
-
非常感谢您的帮助!!!!你太棒了。实际上,如果可能的话,我希望使用三个下拉菜单(以及 27 个输出)来创建更多选项。那可能吗?另外 - 当没有选择任何内容或重置选择时,我将如何隐藏 div?非常感谢。
标签: javascript jquery html drop-down-menu