JavaScript 在按钮单击时加载页面 [英] JavaScript load a page on button click

查看:27
本文介绍了JavaScript 在按钮单击时加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在这里完成一项非常简单的任务,我希望能够单击页面上的按钮并将其带到另一个页面.我试过 window.location.href 和其他一些东西,但它什么也没做.我尝试了不同的平台和不同的浏览器,结果都一样.

I am trying to do a very simple task here, I would like to be able to click a button on a page and have it take me to another page. I have tried window.location.href, and a bunch of other things and it does nothing. I have tried different platforms and different browsers, all with the same result.

我知道它可以调用一个函数,但我就是无法加载新页面.此外,这一切都在我的本地文件系统中,并且两个页面都处于同一级别(但我也尝试加载像 www.apple.com 这样的外部页面).

I know that it can call a function but I just cannot get the new page to load. Also this is all in my local file system and both pages live at the same level (but I have also tried to load an external page like www.apple.com).

有什么想法吗?

谢谢帕特里克

推荐答案

重定向页面的简单代码

<!-- html button designing and calling the event in javascript -->
<input id="btntest" type="button" value="Check" 
       onclick="window.location.href = 'http://www.google.com'" />

这篇关于JavaScript 在按钮单击时加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆