2012-02-27 61 views
0

我有一個動態組合框,其URL爲值。一旦特定項目被選中,我需要連接到URL。使用組合框項目自動鏈接到href值

這是我的代碼。

othercompaniesli.innerHTML= '<select onchange="document.location.href(this.value);"> <option VALUE="http://google.com" >Google</option> <option VALUE="http://google.com" >TEST 1</option> <option VALUE="http://google.com" >TEST</option> </select>'; 

這裏一旦選中Google,它需要帶上gogle頁面。上面的代碼在iexplorer7中工作,而不是在Chrome和Firefox中工作。任何人都可以幫助我,我犯了一個錯誤。

回答

0

而不是 「THIS.VALUE」,嘗試 「this.options [this.selectedIndex] .value的」 ......

othercompaniesli.innerHTML= '<select onchange="document.location.href(this.options[this.selectedIndex].value);"> <option VALUE="http://google.com" >Google</option> <option VALUE="http://google.com" >TEST 1</option> <option VALUE="http://google.com" >TEST</option> </select>'; 

編輯 ......這不是上面,它的文檔。 location.href ......你調用它作爲一個功能,它應該是一個任務:

othercompaniesli.innerHTML= '<select onchange="document.location.href = this.options[this.selectedIndex].value;"> <option VALUE="http://google.com" >Google</option> <option VALUE="http://google.com" >TEST 1</option> <option VALUE="http://google.com" >TEST</option> </select>'; 
+0

這是一個僅在IE7中工作正常,並在Firefox和Chrome不工作 – bharathi 2012-02-27 11:34:53

+0

謝謝您help.Its工作適用於所有瀏覽器。 – bharathi 2012-02-27 11:37:23