在html文件之间导航

时间:2014-07-23 06:16:07

标签: javascript html

我有两个html文件index.html和test.html,我想在按下按钮时从索引导航到测试。

我试过了,但效果不好。

function change_page(){
   console.log("change_page");
   $('body').load( "test.html");
} 


<input type="button" value="create page" onclick="change_page();"/>

如果你知道更好的方法,请告诉我。

3 个答案:

答案 0 :(得分:2)

function change_page(){
  window.location.href = "test.html";
} 


<input type="button" value="create page" onclick="change_page()"/>

答案 1 :(得分:2)

解决方案: 1:使用锚标签在页面之间切换 2.如果你真的想使用Javascript,你可以这样做

function change_page(){
   // similar behavior as an HTTP redirect
   window.location.replace("test.html");
   //or
   // similar behavior as clicking on a link
   window.location.href = "test.html";
}; 

答案 2 :(得分:1)

您可以使用anchor代码href属性来浏览其他网页,例如

 <a href="test.html">Test Page</a>

OR

你可以试试这个

 <input type="button" value="create page" onclick="location.href='test.html'"/>