2016-10-24 3 views
0

Drupal Commerceの製品ページには、サイズオプションがあります。 1つのサイズオプションだけを持つ選択タグに対してCSSを調整する必要があります。これは私の無駄なjqueryの試みです:Drupalの製品ページ:オプションが1つしかない場合は、選択タブでcssを調整する必要があります。

if($(".page-store select.form-select option:selected").index()==0) { 
    $(page-store select.form-select).addClass("one-option-only"); 
}; 

どうすればいいですか?

答えて

0

チェック.children("option").length

$(document).ready(function() { 
    $(".page-store select.form-select").each(function() { 
    if ($(this).children("option").length === 1) { 
     $(this).addClass("one-option-only"); 
    } 
    }); 
}); 
+0

パーフェクト!ありがとうございました! – brij2136

+0

あなたは歓迎です@ brij2136 :)、いつでも助けてうれしいです。 –

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'); 
    } 
}); 
関連する問題