在新窗口中打开dd菜单选项

时间:2012-01-22 12:18:27

标签: html drop-down-menu

我在下拉菜单中使用以下代码,但我希望在新窗口中打开所选选项。我该如何更改此代码才能使其正常工作?

<form name="blah_blah">
<select name="ddmenu_name" style="width: 80% !important;">
<option value="first_option_name" selected>option display name</option>
<option value="1st link to content">1st option name</option>
<option value="2nd link to content">2nd option name</option>
</select>
<input type="button" name="Submit" value="Go!" onClick="top.location.href = this.form.ddmenu2.options[this.form.ddmenu2.selectedIndex].value;
return false;">
</form>

谢谢!

1 个答案:

答案 0 :(得分:2)

见下文......

<强>的index.html

<html>
<body>
<form name="blah_blah">
<select name="ddmenu_name" id="ddmenu_name" style="width: 80% !important;">
<option value="first_option_name" selected>option display name</option>
<option value="page1.html">1st option name</option>
<option value="page2.html">2nd option name</option>
</select>
<input type="button" name="Submit" value="Go!" onClick="window.open(ddmenu_name.value,'newtab')">
</form>
</body>
</html>

<强> page1.html

<html>
<body>
Page 1
</body>
</html>

<强> page2.html

<html>
<body>
Page 2
</body>
</html>

希望这是你需要的东西!!!

祝你好运!!!

更新1

如果您想在选择选项后快速打开新窗口(而不是按下Go按钮),则下面是代码

<html>
<body>
<form name="blah_blah">
<select name="ddmenu_name" id="ddmenu_name" style="width: 80% !important;"  onChange="window.open(ddmenu_name.value,'newtab'">
<option value="first_option_name" selected>option display name</option>
<option value="page1.html">1st option name</option>
<option value="page2.html">2nd option name</option>
</select>
</form>
</body>
</html>