我想创建一个类似于链接的HTML按钮。因此,当您单击按钮时,它将重定向到页面。我希望它尽可能地易于访问。
我也希望这样做,因此URL中没有任何多余的字符或参数。
我该如何实现?
根据到目前为止发布的答案,我目前正在这样做:
<form method="get" action="/page2">
<button type="submit">Continue</button>
</form>
但这是在Safari和Internet Explorer中,它在URL的末尾添加了问号字符。我需要找到一种不会在URL末尾添加任何字符的解决方案。
还有其他两种解决方案:使用JavaScript或设置链接的样式以使其看起来像按钮。
使用JavaScript:
<button onclick="window.location.href='/page2'">Continue</button>
But this obviously requires JavaScript, and for that reason it is less accessible to screen readers. The point of a link is to go to another page. So trying to make a button act like a link is the wrong solution. My suggestion is that you should use a link and style it to look like a button.
<a href="/link/to/page2">Continue</a>
If what you need is that it will look like a button, with emphasis on the gradient image, you can do this: