html5怎样设置button按钮跳转页面

WBOY
WBOY原创
2021-12-30 16:37:129780浏览

方法:1、利用“<button onclick="window.location.href=跳转地址">”语句设置;2、利用“<a href=跳转地址><button>按钮</button></a>”语句用a标签包裹button元素设置。

本教程操作环境:windows10系统、HTML5版、Dell G3电脑。

html5怎样设置button按钮跳转页面

1、利用onclick点击事件和window.location.href属性给按钮元素添加点击事件进行跳转页面。

语法如下:

<button onclick="window.location.href=跳转地址">按钮</button>

示例如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<button onclick="window.location.href='https://www.baidu.com/'">按钮</button>
</body>
</html>

输出结果:

+5.gif

2、利用a标签将button元素包裹起来,利用a标签的href属性设置跳转地址即可。

示例如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<a href="https://www.baidu.com/"><button>按钮</button></a>
</body>
</html>

输出结果与上述结果相同。

推荐教程:《html视频教程

以上就是html5怎样设置button按钮跳转页面的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。