我尝试创建一个下拉菜单,在选择某个选项(是)时会显示更多内容。我尝试使用bootstrap手风琴功能,但没有成功。我已经创建了下拉和手风琴的bootply,就像我希望它如何工作的一个例子。 http://bootply.com/64676 - 所以,点击下拉列表中的“是”,下方会打开手风琴,其中包含与该答案相关的内容。
<label>Do you have any children?</label>
<select>
<option>Select:</option>
<option>Yes</option>
<option>No</option>
</select>
<!-- Example of how I want the above working -->
<p>Name of your hotel - <a class="accordion-toggle" data-toggle="collapse" href="#hotel">Why do we need this?</a>
</p>
<!-- Popup hidden content -->
<div id="hotel" class="accordion-body collapse">
<div class="alert">
<h4>Content here!</h4>
<p>blurb - how many?</p>
</div>
答案 0 :(得分:0)
首先你应该检查你的选项值属性,我把这个例子放在http://jsfiddle.net/bnJvG/
<label>Do you have any children?</label>
<select name="children">
<option value="">Select:</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<div id="hotel" for-field="children" for-value="yes" class="accordion-body collapse">TEST</div>
和de JS
$('select[name="children"]').change(function(event){
var selected = $(this).find('option:selected');
var value = selected.attr("value");
var name= $(this).attr("name");
var selector = '[for-field="'+name+'"]';
$('.accordion-body'+selector).addClass('collapse');
var selectorForValue = selector+'[for-value="'+value+'"]';
var selectedPanel = $('.accordion-body'+ selectorForValue );
selectedPanel.removeClass('collapse');
})