怎么用JavaScript实现按一个按钮然后跳转页面

如题所述

使用如下javascript代码可以实现页面跳转:

window.location.href = url; // 跳转到url页面
location.href = url;        // 这样也行

实例演示如下:

1、关键代码

<input type='button' value='前往百度' onclick="location.href = 'https://www.baidu.com/'"/>

2、效果演示

温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2017-09-28
或者<input name="xx" value="xxx" type="button" onclick="windows.location.href='路径'">

如果有父窗体 想让整个页面都跳转
<input name="xx" value="xxx" type="button" onclick="top.location.href='路径'">本回答被提问者采纳
第2个回答  2006-04-21
<input name="xx" value="xxx" type="button" onclick="this.location.href='路径'">
相似回答