2011-08-09 31 views
0

我一直在爲一個實習工作的WordPress的網站,我想要在頁面中嵌入JavaScript代碼來創建一個下拉菜單瀏覽器瀏覽到選定的頁面。下拉導航菜單在Wordpress中使用Javascript

我想知道,有什麼特別的,你需要做的,讓js工作在WP頁面? 我嘗試使用發佈選項的HTML端嵌入在頁面下面的代碼:

<script language="javascript" type="text/javascript"> 
<!-- 
function menu_goto(menuform) 
{ 
    // see http://www.thesitewizard.com/archive/navigation.shtml 
    // for an explanation of this script and how to use it on your 
    // own site 

    var baseurl = "173.236.164.86/where-to-buy/" ; 
    selecteditem = menuform.newurl.selectedIndex ; 
    newurl = menuform.newurl.options[ selecteditem ].value ; 
    if (newurl.length != 0) { 
     top.location.href = baseurl + newurl ; 
    } 
} 
//--> 
</script> 

<form action="dummyvalue"> 
<select name="newurl" onchange="menu_goto(this.form)"> 
<option value="" selected="selected">----- Select A Product -----</option> 
<option value="vene-prototype-version/">VENE Prototype Version</option> 
<option value="configuration-vene-version/">VENE Configuration Version</option> 
<option value="customized-vene-version/"> VENE Customized Version</option> 
</select> 
</form> 

出現下拉菜單,但未能重定向更改瀏覽器。 我已經嘗試了使用標籤頁面中的代碼,該代碼也沒有效果。

http://173.236.164.86/where-to-buy/

感謝您的幫助!

回答

0

開發者工具在你的JS中顯示一個分析錯誤。大概從WP自動插入段落回報。刪除JS中的所有空白和回車,然後嘗試。

+0

啊,這個伎倆,感謝您的幫助! – Christian