我在magento中找到了选项框默认值:
/app/design/frontend/default/mytheme/template/catalog/product/view/type/options/configurable.phtml
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
显示&#39;选择一个选项...&#39;作为默认值
我试试
<script>
$(function() {
$("#attribute525 option:first-child").attr("selected", true); //color
$("#attribute272 option:first-child").attr("selected", true); //size
});
</script>
将每个属性的默认值设置为每个属性的第一个选项
但它没有用。
答案 0 :(得分:0)
在您的档案中
app/design/frontend/default/mytheme/template/catalog/product/view/type/options/configurable.phtml
正下方
var spConfig = new Product.Config(< ?php echo $this->getJsonConfig() ?>);
粘贴JS代码
spConfig.setInitialState = function(dropdown_id)
{
//select dropdown
var dropdown = $(dropdown_id);
//remove empty option from dropdown so it is not selectable after initial selection
dropdown[0].remove();
//change selections in dropdowns
for(index = 0; index < dropdown.length; index++)
{
if(dropdown[index].value != "")
{
dropdown.selectedIndex = index;
var element = dropdown;
var event = 'change';
//fire events
if(document.createEventObject)
{
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)
}
else
{
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true );
return !element.dispatchEvent(evt);
}
}
}
};
<?php foreach($_attributes as $_attribute): ?>
spConfig.setInitialState("attribute<?php echo $_attribute->getAttributeId() ?>")
<?php endforeach; ?>
这将在产品视图页面
上自动选择可配置选项