我有这3个下拉列表。我只想根据第一个DDL中选择的值显示1个下拉列表。有人可以帮我弄这个吗 :
HTML:
<div class="field">
<label for="message_for">Message For</label>
<select id="message_for" name="message_for" title="Message For" >
<option value='shop'>Shops</option>
<option value='offers'>Offers</option>
<option value='events'>Events</option>
<option value='consultancy'>Consultancy</option>
</select>
</div>
<div class="field1">
<label for="message_type">Message Type</label>
<select id="offer_type" name="offer_type" title="Offer Type" >
<option value='special'>Special</option>
<option value='recommend'>Recommended</option>
<option value='day'>Offer of the Day</option>
<option value='hot'>Hot Offer</option>
</select>
</div>
<div class="field2">
<label for="message_type">Message Type</label>
<select id="shop_type" name="shop_type" title="Shop Type" >
<option value='mall'>Mall</option>
<option value='warehouse'>Warehouse</option>
<option value='food'>Food</option>
<option value='banquet'>Banquet</option>
<option value='service'>Service</option>
<option value='cosmetics'>Cosmetics</option>
<option value='fashion'>Fashion</option>
</select>
</div>
<div class="field3">
<label for="message_type">Message Type</label>
<select id="event_type" name="event_type" title="Event Type" >
<option value='social'>Social</option>
<option value='other'>Other</option>
</select>
</div>
意味着如果我在第一个DDL中选择商店,则第二个DDL应该是DIV field2
最佳答案
基本上,这个想法是使用jquery获取message_for
select的值,并根据其值显示或隐藏其他选择。
$("#message_for").on("change", function(){
if($(this).val() == "shop"){
$(".field1").show();
}
//here add more cases to show relevant selects
});
我已经为您创建了这个jsfiddle-https://jsfiddle.net/guranjanpsingh/h9prdxyy/2/
关于javascript - 使用JavaScript的下拉列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29437993/