2

我正在尝试转换:

<?php if($this->getCurrencyCount()>1): ?>
    <div class="currency">
        <?php foreach ($this->getCurrencies() as $_code => $_name): ?>
            <?php if($_code==$this->getCurrentCurrencyCode()): ?>
                <span title="<?php echo $_name ?> - <?php echo $_code ?>" class="currency-code" style="background-image: url(<?php echo $this->getSkinUrl('images/').$_code.'.png'?>);"><?php echo $_code ?></span>
            <?php else: ?>    
                <a href="<?php echo $this->getSwitchCurrencyUrl($_code) ?>" class="currency-code" style="background-image: url(<?php echo $this->getSkinUrl('images/').$_code.'.png'?>);" title="<?php echo $_name ?> - <?php echo $_code ?>"><?php echo $_code ?></a>
            <?php endif; ?>
        <?php endforeach; ?>

    </div>

<?php endif; ?>

它在 Magento 的电子商务网站中显示货币,所有这些都在一行中,以供选择。

所以我先把代码改成无序列表:

<?php if($this->getCurrencyCount()>1): ?>
    <div class="currency"><ul class="selectdropdown">
        <?php foreach ($this->getCurrencies() as $_code => $_name): ?>
            <?php if($_code==$this->getCurrentCurrencyCode()): ?>
                <li class="selected"><span title="<?php echo $_name ?> - <?php echo $_code ?>" class="currency-code" style="background-image: url(<?php echo $this->getSkinUrl('images/').$_code.'.png'?>);"><?php echo $_code ?></span></li>
            <?php else: ?>    
                <li><a href="<?php echo $this->getSwitchCurrencyUrl($_code) ?>" class="currency-code" style="background-image: url(<?php echo $this->getSkinUrl('images/').$_code.'.png'?>);" title="<?php echo $_name ?> - <?php echo $_code ?>"><?php echo $_code ?></a></li>
            <?php endif; ?>
        <?php endforeach; ?>
    </ul>
    </div>

<?php endif; ?>

然后,按照此处的说明进行操作:https ://stackoverflow.com/a/6760507 我正在尝试将其转换为选择时加载新页面(在href中)的选择:

<script>
$('ul.selectdropdown').each(function(){
var list=$(this),
    select=$(document.createElement('select')).insertBefore($(this).hide()).change(function(){
  window.location.href=$(this).val();
});
$('>li a', this).each(function(){
  var option=$(document.createElement('option'))
   .appendTo(select)
   .val(this.href)
   .html($(this).html());
  if($(this).attr('class') === 'selected'){
    option.attr('selected','selected');
  }
});
list.remove();
});
</script>

我找不到问题所在。Jquery 已正确导入。目前我只看到一个有序列表:

<ul class="selectdropdown">

                <li><a href="http://..." class="currency-code" style="background-image: url(...);" title="Dollaro Australiano - AUD">AUD</a></li>

                <li><a href="http://..." class="currency-code" style="background-image: url(...);" title="Dollaro Canadese - CAD">CAD</a></li>

...
                        </ul>

然后,脚本

有人能帮我吗?谢谢

4

1 回答 1

0

jquery 是否与 magento 冲突。尝试无冲突。检查 jQuery 中的任何错误

于 2013-04-21T19:49:11.757 回答