15621857753

html中button添加跳转超链接a的方法

来源:齐鲁建站 栏目:开发教程 阅读: 日期:2022-06-16

今天写代码突然遇到一个小问题,就是在演示的纯静态怎么让BUTTON跳转下一页呢,本文介绍了html中button添加跳转超链接a的方法,button是按钮元素,不能直接使用超链接A,只能使用onclick事件,具体怎么写,看看正文介绍吧。

下面来说说html中button添加跳转超链接a的方法。

在写静态演示页,假如有下面这行代码:

<button class="button button-block bg-main size-big h60 margin-top-large">登录</button>

想要跳转到下一个页面,怎么实现呢?

使用超级链接<a>方法可以吗?也就是:

<a href=""><button class="button button-block bg-main size-big h60 margin-top-large">登录</button></a>

这样可以吗?经测试,不可以的。

那么怎么处理呢?只能使用onclick事件,写法如下:

<button onclick="window.open('首页.html')" class="button button-block bg-main size-big h60 margin-top-large">登录</button>

这样就可以了,试试看吧。

展开