gpt4 book ai didi

php - jquery向多个选择下拉列表添加属性

转载 作者:行者123 更新时间:2023-12-01 08:12:55 26 4
gpt4 key购买 nike

我有代码(根据布拉德·克里斯蒂的建议进行编辑):

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");

它成功地将“selected”属性($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");

两个循环都失败了!

感谢您的提示!

最佳答案

上面的代码显然是混合了 javascript 和 php,但无法判断它可能出了什么问题。您应该检查(通过在浏览器中查看源代码)生成的 javascript 代码是否符合您的预期。如果可能的话,在此处发布生成的 JavaScript。

关于php - jquery向多个选择下拉列表添加属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12372465/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com