[英]Why isn't this javascript redirecting?
我想讓用戶單擊一個按鈕並將他/她重定向到另一個站點,我以前使用過 window.location 但由於某種原因這次它不起作用。 我確定選擇器是正確的,就像我更改window.location
以alert
它每次都發出警報一樣,所以我不知道我做錯了什么。
$('#show').click(function(){
if($('select[name="customers"]').val() == '')
window.location.replace = 'http://google.com/';
});
你必須使用
window.location.replace("http://google.com"); // This is like http redirect
或者
window.location.href = "http://google.com"; // This is like a link
你不能做window.location.replace= "http://google.com";
它是一種方法,而不是屬性。
window.location.replace('http://google.com/');
那不應該是windows.location.href =...
嗎?
只設置window.location.href
。 像這樣:
window.location.href = 'http://google.com/';
嘗試: window.location = 'http://google.com'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.