2013-11-27 69 views
0

嗨在magento中選擇導航菜單後,如何獲取onchange值? 我試圖在topmenu.phtml下面的代碼,但它不能正常顯示頁面沒有找到 但它工作不正常。我該怎麼辦?如何在magento中選擇導航菜單後獲得更改值?

+0

這裏是topmenu.phtml <選擇的id =」 nav「class =」nav「onchange =」setLocation(this.value)「> <?php echo $ _menu?> –

回答

0

,你可以嘗試這樣的事情

<select id="nav" class="nav" onchange="if (this.value) window.location.href=this.value"> 
+0

我試圖但在網址工作404找不到1 –

+0

什麼是您的選擇選項的價值 –

+0

選擇選項值獲取名稱 –

0

更新Topmenu.php代碼與下面的代碼。

刪除此:

$html .= '<option ' . $this->_getRenderedMenuItemAttributes($child) . '>'; 
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>' . $this->escapeHtml($child->getName()) . '</span></a>'; 

if ($child->hasChildren()) { 
    if (!empty($childrenWrapClass)) { 
     $html .= '<div class="' . $childrenWrapClass . '">'; 
    } 
    $html .= '<ul class="level' . $childLevel . '">'; 
    $html .= $this->_getHtml($child, $childrenWrapClass); 
    $html .= '</ul>'; 
    if (!empty($childrenWrapClass)) { 
     $html .= '</div>'; 
    } 
} 
$html .= '</option>'; 

添加以下代碼:

$html .= '<option value="' . $child->getUrl() . '" '>'. $this->escapeHtml($child->getName()) . '</option>'; 
if ($child->hasChildren()) { 
    $html .= $this->_getHtml($child, $childrenWrapClass); 
} 

而且更新選擇onchange代碼與下面的代碼:

onchange="if (this.value) window.location.href=this.value" 
+0

對不起,得到錯誤解析錯誤:語法錯誤,意外'。'在線125 –

+0

D:\ xampp \ htdocs \ littletreasures \ app \ code \ local \ Mage \ Page \ Block \ Html \ Topmenu.php使用更新後的代碼。 –

相關問題