我想根据用户从两个下拉列表中的选择显示一个 div。
虽然我将向用户显示 3 个下拉选项,但我只会根据前两个的选择生成输出:
这意味着我将根据用户的选择总共有 9 个可能的输出:
- 海滩 --> 寒冷
- 海滩 --> 快节奏
- 海滩 --> 两者
- 博物馆 --> 寒意
- 博物馆 --> 快节奏
- 博物馆 --> 两者
- 山 --> 寒意
- 山脉 --> 快节奏
- 山 --> 两者
只是为了类似的参考,几个月前,我使用以下脚本根据 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 个选项中的)显示在下面。
非常感谢!