Javascript Magento可配置产品-下拉菜单选择选项并保持其他下拉选择不变

Javascript Magento可配置产品-下拉菜单选择选项并保持其他下拉选择不变,javascript,magento,configurable-product,Javascript,Magento,Configurable Product,我的可配置产品页面上有以下javascript,它从下拉菜单中删除了默认的“选择选项…”。当我更改其中一个选项时,其他下拉菜单默认为“选择选项…”。我希望在进行选择时下拉菜单保持不变 示例:如果我更改“颜色”下拉列表中的选择,我希望“类型”和其他选项保留其以前选择的选项。我在下面的图片中展示了最终目标 <?php $_product = $this->getProduct(); $_attributes = Mage::helper('core')->decorateAr

我的可配置产品页面上有以下javascript,它从下拉菜单中删除了默认的“选择选项…”。当我更改其中一个选项时,其他下拉菜单默认为“选择选项…”。我希望在进行选择时下拉菜单保持不变

示例:如果我更改“颜色”下拉列表中的选择,我希望“类型”和其他选项保留其以前选择的选项。我在下面的图片中展示了最终目标

<?php
$_product    = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
    <dl>
    <?php foreach($_attributes as $_attribute): ?>
        <dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
        <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
            <div class="input-box">
                <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" onchange="update_<?php echo $_attribute->getAttributeId() ?>();" class="required-entry super-attribute-select">
                    <option><?php echo $this->__('Choose an Option...') ?></option>
                  </select>
              </div>
        </dd>
    <?php endforeach; ?>
    </dl>

<script type="text/javascript">
//Dropdown option changing
    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); 

    //we create new function
    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; ?>
</script>

*
class=“last”>
); 
//我们创造了新的功能
spConfig.setInitialState=函数(下拉菜单_id){
//选择下拉列表
var dropdown=$(下拉菜单id);
//从下拉列表中删除空选项,使其在初始选择后不可选择
下拉列表[0]。删除();
//更改下拉列表中的选择
对于(索引=0;索引
这些是默认选项

这是颜色更改时发生的情况

这就是我希望发生的事情