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

html5怎样设置button按钮跳转页面,第1张

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

方法: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按钮跳转页面的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/699238.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-23
下一篇 2022-04-23

发表评论

登录后才能评论

评论列表(0条)

保存