我有两个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();"/>
如果你知道更好的方法,请告诉我。
答案 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'"/>