简体   繁体   English

选择标签并转到页面选项

[英]Select tag and go to page option

Can anyone explain why below example does not work? 谁能解释为什么下面的示例不起作用? I'd like to impelment dropdown that will redirect to other sites based on the option selected. 我想推动下拉菜单,该下拉菜单将根据所选选项重定向到其他网站。

http://jsfiddle.net/5swk8/6/ http://jsfiddle.net/5swk8/6/

function go()
{
    window.location=document.getElementById("menu-dropdown").value;
}

It is saying as 'Uncaught ReferenceError: go is not defined' because the go() method is wrapped in onload. 之所以说这是“未捕获的ReferenceError:未定义go”,是因为go()方法包装在onload中。 Change the wrap option to body, then it will work. 将wrap选项更改为body,然后它将起作用。

In the Frameworks & Extensions panel , set onLoad to No wrap - in <body> .it will work Frameworks & Extensions panel ,将onLoad to No wrap - in <body>设置onLoad to No wrap - in <body>它将起作用

DEMO 演示

Without a separate function 没有单独的功能

<select id="mySelect" onChange="document.location = this.value" value="GO">
    <option>Select</option>
    <option value="http://www.microsoft.com">Test</option>
</select>

Demo: http://jsfiddle.net/2ekmM/1/ 演示: http//jsfiddle.net/2ekmM/1/

You have an error in redirecting the page. 您在重定向页面时出错。 It is 它是

window.location.href="";

your code is right only thing you have move your go function inside body I updated your code in jsfiddle. 您的代码是正确的,只有在体内移动了go函数之后,我才在jsfiddle中更新了代码。

jsfiddle.net/mannejkumar/5swk8/11/ jsfiddle.net/mannejkumar/5swk8/11/

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

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