简体   繁体   English

自动链接到带有组合框项目值的href

[英]Auto link to href with combo box items value

I have a dynamic combo box which has the URL as the value. 我有一个动态组合框,其URL为值。 I need to connect to the URL once the particular item is get selected. 选择特定项目后,我需要连接到URL。

This is my code. 这是我的代码。

  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>';  

Here once the Google is selected it need to take the gogle page. 在这里,一旦选择了Google,就需要进入gogle页面。 the above code is working in iexplorer7 and not working in chrome and firefox. 上面的代码在iexplorer7中工作,而在chrome和firefox中工作。 Can any one help me where i made a mistake. 在我犯错的地方,谁能帮助我。

Instead of "this.value", try "this.options[this.selectedIndex].value"... 尝试使用“ this.options [this.selectedIndex] .value”代替“ this.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>';  

EDIT ... it's not the above, it's the document.location.href... you're calling it as a function, it should be an assignment: 编辑 ...不是上面的,它是document.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>';  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM