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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:48:30  来源:igfitidea点击:

input onclick new tab

htmlonclick

提问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/

现场演示 - http://jsfiddle.net/im4aLL/tzp4H/

回答by imulsion

function open_in_new_tab(url )
{
  var win=window.open(url, '_blank');
  win.focus();
}

Call that function when you want to open a link in a new tab. Also check hereand here

当您想在新选项卡中打开链接时调用该函数。也检查这里这里

回答by gyrofly

Regarding your updated answer to your original post:

关于您对原始帖子的更新回答:

Adding ,'_blank'after the .valuelike 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>