javascript - 按钮/下拉菜单在新窗口中打开
问题描述
所以,我做了一个小网站,它有一些下拉选项供我们公司使用。我正在尝试获取我创建的“开始”按钮,以从新选项卡中的下拉菜单中打开链接,这样您就不会丢失页面,因为它当前在与帮助页面相同的选项卡中打开链接。我将在下面粘贴一个示例,如果我能得到任何帮助,那将是
<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();
}
解决方案
您可以使用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();
}
推荐阅读
- python - 如何减少列表遍历器的执行时间限制
- android - 在同一个按钮上使用 android:background@drawable 和 stateListAnimator 会导致问题
- java - 找不到类“android.view.menu”
- python-3.x - CSV 文件未使用 pandas 数据框完全或正确上传
- php - 可以使用 PHP 的 password_hash 在 SQL 中设置默认用户的密码吗?
- python - 在 Mayavi 中使用 quiver3d() 绘制 3D 矢量场
- rust - 即使在 `&mut T` 存在的情况下,我是否可以将生命周期参数强制为更短的生命周期(健全)?
- parsing - 方案/球拍:如何在定义语法时重复
- ios - Admob IOS swift GDPR 同意
- powershell - Powershell-如何通过变量识别数组上匹配的字符串索引