Html 如何制作指向另一个页面的按钮链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34821728/
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
How can I make a button link to another page?
提问by bfunphoto
This is my HTML so far
到目前为止,这是我的 HTML
<button type="button" formaction="contact.html">Get In Touch!</button>
For some reason when I click on the button in a browser it doesn't take me to the contact.html page. All the pages that came up in google helped me learn new button attributes, but I couldn't figure out how to make the page redirect on click.
出于某种原因,当我单击浏览器中的按钮时,它不会将我带到 contact.html 页面。谷歌中出现的所有页面都帮助我学习了新的按钮属性,但我不知道如何在点击时重定向页面。
回答by Daniel
If you are using bootstrap, you can use this to do it for you:
如果您正在使用引导程序,您可以使用它来为您执行此操作:
<a href="#" class="btn btn-info" role="button">Link Button</a>
See http://www.w3schools.com/bootstrap/bootstrap_buttons.asp
回答by Maihan Nijat
Try the following:
请尝试以下操作:
<input type="button" onclick="location.href='contact.htm';" value="Contact" />
The better way is that you surround the above code with <form></form>
.
更好的方法是将上面的代码用<form></form>
.
回答by Adnan Toky
Try these methods:
试试这些方法:
<!-- Using window.location.href = 'URL' -->
<button onclick='window.location.href = "https://stackoverflow.com"'>
Click Me
</button>
<!-- Using window.location.replace('URL') -->
<button onclick='window.location.replace("https://stackoverflow.com")'>
Click Me
</button>
<!-- Using window.location = 'URL' -->
<button onclick='window.location = "https://stackoverflow.com"'>
Click Me
</button>
<!-- Using window.open('URL') -->
<button onclick='window.open("https://stackoverflow.com","_self","","")'>
Click Me
</button>
<!-- Using window.location.assign('URL') -->
<button onclick='window.location.assign("http://www.stackoverflow.com")'>
Click Me
</button>
<!-- Using HTML form -->
<form action='https://stackoverflow.com' method='get'>
<input type='submit' value='Click Me'/>
</form>
<!-- Using html anchor tag -->
<a href='https://stackoverflow.com'>
<button>Click Me</button>
</a>