Html 输入 onclick 新标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16786813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
input onclick new tab
提问by Dan Howes
<form name="test">
<select name="choose" style="width:300px;">
<option selected="">Select option</option>
<option value="http://url.com">Test</option>
</select>
<input onclick="location=document.test.choose.options[document.test.choose.selectedIndex].value;" value="Take me there!" type="button"></p>
</form>
Im using the following to make a dropdown list and was just wondering how i would make selected open in a new tab and not in its own window
我使用以下内容制作下拉列表,只是想知道如何在新选项卡中而不是在自己的窗口中打开选择
Works fine as it is just need it to open in a new tab.
工作正常,因为它只需要在新选项卡中打开。
* Edit *
* 编辑 *
This worked as needed thanks
这在需要时有效,谢谢
<input onClick="window.open(document.test.choose.options[document.test.choose.selectedIndex].value);" value="Take me there!" type="button">
回答by HADI
try window.open
试试 window.open
window.open('http://www.google.com');
update
更新
live demo - http://jsfiddle.net/im4aLL/tzp4H/
回答by imulsion
回答by gyrofly
Regarding your updated answer to your original post:
关于您对原始帖子的更新回答:
Adding ,'_blank'
after the .value
like so:
,'_blank'
在.value
像这样之后添加:
<input type="button" onClick="window.open(document.test.choose.options[document.test.choose.selectedIndex].value,'_blank');>
Actually opens in a new tab instead of an entirely new browser window.
实际上在新选项卡中打开,而不是在全新的浏览器窗口中打开。
回答by Mujeeb Ishaque
Nothing advanced or similar. You just need to add _blank as the following example demonstrate.
没有什么先进的或类似的。您只需要添加 _blank,如下例所示。
<a href="someLink.html" target="_blank">
<button>Visit my Github</button>
</a>