我有代码(编辑后,布拉德·克里斯蒂建议):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