首页 > 解决方案 > 按钮/下拉菜单在新窗口中打开

问题描述

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

<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();
}

标签: javascripthtmljquery

解决方案


您可以使用window.open()with_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();
}

推荐阅读