我正在处理一个 jquery 下拉菜单。通常我的下拉菜单中有多个选项可供选择,但对于某些产品,只有一个选项我希望脚本能够在只有一个选项的情况下选择值并禁用下拉菜单。现有代码是:
RonisCatalog.selectSwatches = function(element, options){
if (jQuery('body .swatches-container').size()==0)
return ;
else
var selectOptions = jQuery(element).find('option'),
selectOptionsValues = {};
var selectLabel = '';
jQuery.each(selectOptions,function(idx,selectOption){
if (jQuery(selectOption).val()=='')
selectLabel = jQuery(selectOption).html();
selectOptionsValues[jQuery(selectOption).val()] = jQuery(selectOption).val();
});
jQuery('body .swatches-container .swatch-type-id-'+element.attributeId).parents('.swatch-list-continer').children('.swatch-list-label').html('<label id="attribute'+element.attributeId+'_label" >Select '+selectLabel+'</label>');
jQuery('body .swatches-container .swatch-type-id-'+element.attributeId+' .swatch-option').addClass('swatch-disabled').removeClass('swatch-active');
jQuery.each(options,function(idx,option){
if (typeof selectOptionsValues[option.id] != 'undefined')
jQuery('body .swatches-container .swatch-type-id-'+element.attributeId+' .swatch-option-id-'+option.id).removeClass('swatch-disabled');
});
};
我想在两者之间使用这个选项:
else if (jQuery('body .swatches-container').size()==1) {
}
和如上所述的功能。
任何帮助,将不胜感激。
谢谢