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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8847270/
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-24 07:46:47  来源:igfitidea点击:

how to give a href inside the button tag in html

javascripthtml

提问by Raju.allen

i need to open two links when a button is clicked in the html page. I figured it as by calling onclick function and creating anchor tag using createElement in Javascript. But how to include another link?? Is there a way to give a href in button tag??

当在 html 页面中单击按钮时,我需要打开两个链接。我认为它是通过调用 onclick 函数并在 JavaScript 中使用 createElement 创建锚标记来实现的。但是如何包含另一个链接?有没有办法在按钮标签中给出一个href??

回答by Chuck Norris

You can simply do that with javascript

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

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

And if you want to open one of that links in curren window you can replace window.open by this

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

window.location = url1;

回答by Amit

  <input type="button" value="Double Clicker"  onclick="window.open(&quot;http://www.google.com/&quot;); window.open(&quot;http://www.youtube.com/&quot;);" />

see this linkfor further information,

请参阅此链接以获取更多信息,

回答by Payam Omrani

You need to use a javascript event to make the page go somewhere

您需要使用 javascript 事件使页面转到某处

<input type="button" name="button1" value="Go To Url" onClick="window.navigate('URL')"> 

回答by user3519216

You can also use

你也可以使用

location.href=" ";`

回答by DAre G

why dont u use bootstrap

你为什么不使用引导程序

 <a href="#" class="btn btn-default">

It displays a button with link going to what is mentioned in href

它显示一个按钮,链接指向 href 中提到的内容

回答by Marc Simon

Try to see what the location object can do => http://www.w3schools.com/jsref/obj_location.aspYou should be able to load two tab.

尝试查看位置对象可以做什么 => http://www.w3schools.com/jsref/obj_location.asp您应该能够加载两个选项卡。