专业编程基础技术教程

网站首页 > 基础教程 正文

HTML中button标签点击实现页面跳转的三种方法

ccvgpt 2024-08-03 12:45:40 基础教程 19 ℃

方法1:使用onclick事件

<input type="button" value="按钮"
onclick="javascrtpt:window.location.href='http://www.baidu.com/'" />

或者直接使用button标签

HTML中button标签点击实现页面跳转的三种方法

<button onclick="window.location.href = 'https://www.baidu.com/'">百度</button>

方法2:在button标签外套一个a标签

<a href="http://www.baidu.com/">
 <button>百度</button>
</a>

或使用

<a href="http://www.baidu.com/"><input type="button" value='百度'></a>

方法3:使用JavaScript函数

<script>
function jump(){
 window.location.href="http://www.baidu.com/";
}
</script>
<input type="button" value="百度" onclick=javascrtpt:jump() />
// 或者<input type="button" value="百度" onclick="jump()" />
// 或者<button onclick="jump()">百度</button>

Tags:

最近发表
标签列表