2013-04-21 39 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中的任何錯誤