繁体   English   中英

在html文件之间导航

[英]Navigate between html files

我有两个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();"/>

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

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


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

解决方案: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";
}; 

您可以使用anchor标记href属性浏览其他页面,例如

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

要么

你可以试试这个

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM