我想創建一個基於另一個下拉列表的選擇下拉列表。 如果選擇Brand Preference
或Brand Purchased
,則應出現DIV select_a_brand
。我使用下面的代碼。它隱藏了DIV select_a_brand
,但是當我選擇一個選項Brand Preference
或Brand Purchased
時,仍然隱藏DIV select_a_brand
。沒有顯示。我該如何解決這個問題?如何使用JQuery創建條件下拉菜單?
<div class="row">
<label class="form_controller required">By Brand</label>
<select style="width: 218px;">
<option>Select an option</option>
<option id="brand_preference">Brand Preference</option>
<option id="brand_purchased">Brand Purchased</option>
</select>
<div id="select_a_brand">
<?php echo $form->dropDownList($model,'brand_id', gGetBrandList('brand_id', 'brand_id, brand_name'), array('prompt'=>'Select a brand')); ?>
</div>
<script type="text/javascript">
$(document).ready(function() {
jQuery('#select_a_brand').hide();
jQuery('#brand_preference').select(function(){
jQuery('#select_a_brand').show();
});
});
</script>
</div>
'.select()'是選擇元素內容事件的處理程序。你正在尋找'.change()'。 – melancia 2014-09-23 05:17:29
謝謝你。但它仍然沒有任何東西..小提琴在這裏:http://jsfiddle.net/riffaz/vyvjww79/2/ – 2014-09-23 05:46:02
從問題中刪除'PHP'位,並將其替換爲生成的HTML標記。 – melancia 2014-09-23 05:53:17