javascript - 如何在html中的按钮标签内给出一个href

标签 javascript html

我需要在 html 页面中单击一个按钮时打开两个链接。我认为它是通过调用 onclick 函数并在 Javascript 中使用 createElement 创建 anchor 标记。但是如何包含另一个链接?有没有办法在按钮标签中提供 href??

最佳答案

你可以简单地用 javascript 做到这一点

window.open(url1);
window.open(url2);

如果你想在当前窗口中打开其中一个链接,你可以用这个替换 window.open

window.location = url1;

关于javascript - 如何在html中的按钮标签内给出一个href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8847270/

相关文章:

javascript - jquery 切换的一个奇怪问题的简单示例

JavaScript 在 Bootstrap 导航栏上传递数据点击

html - 如何在特定索引处的 ngfor 中插入/显示 div

javascript - 使用 indesign 中的脚本获取和设置表格中的文本元素

javascript - 用个人资料链接 javascript 替换用户名

html:将 block 标签转换为内联标签

javascript - 搜索输入被发送到不同页面上的另一个搜索栏

html - 使用来自不同 div 的 anchor 标记或按钮更改幻灯片

javascript - electron v10.1.1 给出 Uncaught TypeError : Cannot read property 'dialog' of undefined, 但相同的代码在 Electron v9.3.0 中有效

javascript - 为每个图像缩略图预览添加删除按钮