html button按钮模拟超链接的三种方法

时间:2017-11-03
我们大家都知道,button按钮只有click方法,一般无法像超链接那样可以进行页面跳转,但是我们可以使用一些特殊方法将button按钮模拟成超链接的行为。本文章向大家介绍html button按钮模拟超链接的三种方法。需要的朋友可以参考一下。

html button按钮模拟超链接的三种方法.

方法一:form表单方法

实现代码:

<form method="get" action="http://www.manongjc.com">
    <button type="submit">Continue</button>
</form>

方法二:window.location.href 方法

代码如下:

<button onclick="window.location.href='http://www.manongjc.com'">Continue</button>

方法三:在button之外添加超链接

<a href="http://www.manongjc.com" target="_blank">
<button>My Button</button>
</a>