方法: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>输出结果:

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中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号