2013-04-21 60 views
2

我想转换:转换列表使用jQuery

<?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> 

然后,脚本

有人能帮助我吗? 谢谢

回答

0

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