我有代碼(編輯後,布拉德·克里斯蒂建議):jQuery的屬性添加到多個選擇下拉菜單
drupal_add_js('
jQuery(document).ready(function(){
jQuery("#selFinishes option").each(function(index) {
if (jQuery(this).val() == ' . $filter_color . ') {
jQuery(this).attr("selected","selected")
}
})
});
', "inline");
它成功地增加了「選擇」屬性($ filter_color通過PHP添加)到所選擇的值。但是,當我的目標多個選擇領域是這樣的:
drupal_add_js('
jQuery(document).ready(function(){
jQuery("#selFinishes option").each(function(index) {
if (jQuery(this).val() == ' . $filter_color . ') {
jQuery(this).attr("selected","selected")
}
})
jQuery("#selThemes option").each(function(index) {
if (jQuery(this).val() == ' . $filter_theme . ') {
jQuery(this).attr("selected","selected")
}
})
});
', "inline");
兩個循環無法正常工作!
感謝提示!
啊是我的猜測..我不得不emtpy值,因爲在某些場合值不存在......我加入下isset整個循環首先檢查變量是否存在! Thanx – NenadP