Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

javascript - JavaScript在按钮点击时加载页面(JavaScript load a page on button click)

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.(我已经尝试过window.location.href,以及其他一些东西,它什么也没做。) I have tried different platforms and different browsers, all with the same result.(我尝试过不同的平台和不同的浏览器,都有相同的结果。)

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).(此外,这一切都在我的本地文件系统中,并且两个页面都处于同一级别(但我也尝试加载外部页面,如www.apple.com)。)

Any thoughts?(有什么想法吗?)

Thanks Patrick(谢谢Patrick)

  ask by Patrick translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Simple code to redirect page(简单的代码重定向页面)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...