2014-07-23 46 views
0

我有兩個html文件index.html和test.html,我想從索引導航到按下按鈕時進行測試。在html文件之間導航

我試過了,但效果不好。

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


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

如果你知道一些更好的方法,請告訴我。

+1

你確定你不使用正常的鏈接(搜索引擎,noJS用戶等)嗎?如果不是,那麼*也不好*意味着什麼? – panther

+0

如果您想使用JavaScript:而不是$('body')。load(「test.html」);試試這個:window.location.href =「test.html」; –

+0

它沒有正常加載 – Rad1

回答

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


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

是的,這是工作! thannnks – Rad1

+0

介意接受它作爲答案? :D @ Rad1 – doniyor

+0

當然!對不起:p – Rad1

1

您可以使用anchor標籤href屬性瀏覽其他頁面像

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

OR

你可以試試這個

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

這當然是要走的路。 –

1

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