[英]Product page in Drupal: Need to adjust css on the select tab if there is only one option (“size”) available
在Drupal Commerce的產品頁面上,某些項目具有尺寸選項,而另一些則沒有。 我需要為只有一個大小選項的那些選擇標簽調整css。 這是我的jQuery嘗試無濟於事:
if($(".page-store select.form-select option:selected").index()==0) {
$(page-store select.form-select).addClass("one-option-only");
};
我該如何實現?
您的邏輯有些不對勁,並且您遇到語法錯誤。
//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');
}
});
檢查.children("option").length
。
$(document).ready(function() {
$(".page-store select.form-select").each(function() {
if ($(this).children("option").length === 1) {
$(this).addClass("one-option-only");
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.