2013-07-04 33 views
-2

我想要使用此功能位置不是函數

function MButton1Click(event) { 
alert("teste2"); 
window.location("teste.php"); 
} 

到另一個頁面,但我發現了一個對象的

位置是不是一個函數

+2

可是錯誤似乎是顯而易見的。當它不是函數時,您將它稱爲函數... – elclanrs

+0

location是一個屬性。嘗試window.location =「http:// ...」 – guy777

回答

2

使用此:

window.location = "teste.php"; 

您的語法是用於功能的。location()但是location是一個對象。

看看在window.location documentations

+0

現在,我沒有收到錯誤,但頁面沒有更改... – user2501387

+0

其他的東西可能會在您獲得此聲明之前破壞您的代碼。這是做到這一點的方法。檢查文檔。 –

+0

'function MButton1Click(event){ window.location.href =「www.google.com」;}' – user2501387

0

location是一個對象。您可以使用它assignreplace功能改變網頁:

// Use this if you want the back button to take you to the current page 
window.location.assign("teste.php"); 

// Use this if you want to remove the current page from the browser's history 
window.location.replace("teste.php"); 

您也可以使用assignment shorthandassign

window.location = "teste.php"; 
+0

現在我沒有收到錯誤,但頁面沒有更改.... – user2501387