【问题标题】:Button/Drop Down open in new window按钮/下拉菜单在新窗口中打开
【发布时间】:2020-05-26 13:28:52
【问题描述】:

所以,我做了一个小网站,它有一些下拉选项供我们公司使用。我正在尝试获取我创建的“开始”按钮,以从新选项卡中的下拉菜单中打开链接,这样您就不会丢失页面,因为它当前在与帮助页面相同的选项卡中打开链接。我将在下面粘贴一个示例,如果我能得到任何帮助,那将是一个

<select id="Polynesian">
  <option value="#">Choose a CMTS</option>
  <option value="http://MYURL1/">Pond</option>
  <option value="http://MYURL2/">Beach</option>
</select>
<button id="go" onclick="gotosite()">Go</button>

这是我为每个按钮创建的按钮 js。

function gotosite() {
  window.location = document.getElementById("GulfPlace").value; // JQuery:  $("#GulfPlace").val();
  window.location = document.getElementById("Polynesian").value; // JQuery:  $("#Polynesian").val();
  window.location = document.getElementById("GrandCaribbean").value; // JQuery:  $("#GrandCaribbean").val();
  window.location = document.getElementById("DunesOfSeagrove").value; // JQuery:  $("#DunesOfSeagrove").val();
  window.location = document.getElementById("PinnaclePort").value; // JQuery:  $("#PinnaclePort").val();
}

【问题讨论】:

  • 嗨!那么您面临的问题是什么?
  • 它只是在同一个窗口中打开页面,这意味着您必须返回或重新打开页面才能使用工具。
  • 这实际上完全破坏了按钮,现在它什么也没有打开。

标签: javascript html jquery


【解决方案1】:

您可以使用window.open()_blank 选项在新标签页中打开

 function gotosite() {
  window.open(document.getElementById("GulfPlace").value,'_blank'); // JQuery:  $("#GulfPlace").val();
  window.open(document.getElementById("Polynesian").value,'_blank'); // JQuery:  $("#Polynesian").val();
  window.open(document.getElementById("GrandCaribbean").value,'_blank'); // JQuery:  $("#GrandCaribbean").val();
  window.open(document.getElementById("DunesOfSeagrove").value,'_blank'); // JQuery:  $("#DunesOfSeagrove").val();
  window.open(document.getElementById("PinnaclePort").value,'_blank'); // JQuery:  $("#PinnaclePort").val();
}

【讨论】:

  • 你这个人,完美!我以前试过这个,但也许我错过了一些简单的东西把它搞砸了!!!感谢您的快速回复!
猜你喜欢
  • 1970-01-01
  • 2011-06-06
  • 1970-01-01
  • 1970-01-01
  • 2020-12-13
  • 2015-09-09
  • 1970-01-01
  • 2016-08-19
  • 1970-01-01
相关资源
最近更新 更多