在Drupal Commerce的产品页面上,某些项目具有大小选项,而其他项目则没有。我需要为那些只有一个尺寸选项的选择标签调整css。这是我的jquery尝试无济于事:
if($(".page-store select.form-select option:selected").index()==0) {
$(page-store select.form-select).addClass("one-option-only");
};
我怎样才能做到这一点?
答案 0 :(得分:0)
你的逻辑有点偏,你的语法错误。
//iterate each select
$('.page-store select.form-select').each(function() {
//see if the current select has exactly one option
if ($(this).find('option').length == 1) {
//add the class
$(this).addClass('one-option-only');
}
});
答案 1 :(得分:0)
检查$(document).ready(function() {
$(".page-store select.form-select").each(function() {
if ($(this).children("option").length === 1) {
$(this).addClass("one-option-only");
}
});
});
。
istringstream