2013-08-01 21 views
1

如何刷新當前URL的下拉框值的onchnage,我嘗試以下,但似乎是一個錯誤刷新當前URL onchange事件處理程序

 <select id='account-select-box' onchange='window.location ='+document.URL+';'> 
      <option selected>Link 1</option> 
      <option >Link 2</option> 
      <option >Link 3</option> 
     </select> 

錯誤是未捕獲的SyntaxError:意外的標記}

+0

有什麼錯誤? – jsalonen

+0

爲什麼不'window.location.href' 如果你想在其他頁面上重定向,試試這個。 –

+0

ne需要使用.href,位置不錯 – mplungjan

回答

2

你有太多的事情

1.修復原密碼

<select id='account-select-box' onchange="window.location=document.URL"> 

2.改進代碼

<select id='account-select-box' onchange="location.reload(1)"> 

問自己爲什麼?你想達到什麼目的?改變選擇時重新加載的重點是什麼?

你的意思

<select id="account-select-box" 
onchange="var loc = this.value; if (loc) location=loc"> 
    <option value="">Please select</option> 
    <option value="http://google.com">Google</option> 
    <option value="http://mdn.com">MDN</option> 
</select> 
+0

但刷新如果我選擇了鏈接2,那麼該選項將重置爲再次鏈接1? – Hulk

+0

代碼應該做什麼?用戶在更改下拉菜單時應該看到的是什麼 – mplungjan

+0

它是假設獲得所有與鏈接2有關的值,然後這是index.html頁面,因此它也重置下拉值 – Hulk