2014-01-27 55 views
0

我在php上使用header,現在我想用jQuery。當功能成功後,jquery自動更改頁面

if ($('form #response').hasClass('success')) { 

    setTimeout("$('form #response').fadeOut('fast')", 5000); 
    return window.location = index.php; 
} 

此行不行 - 我要改變頁面時.hasClass('success')這裏

return window.location = index.php; 

我試着不帶復位輸入代碼再沒有工作。

回答

2

試試這個:

if ($('form #response').hasClass('success')) { 
    setTimeout(function() { 
     $('form #response').fadeOut('fast', function() { 
      window.location.href = "index.php"; 
     }); 
    }, 5000); 
} 

我改變了你的settimeout有一個功能,即要求#responsefadeOut,並且一旦這樣完成它調用window.location.href它變爲index.php

0

window.location需要在頁面附近引用引號。試試這個代碼,而不是:

window.location = 'index.php'; 
0

而不是設置window.location(它返回一個Location對象 - 它是一個只讀屬性),請嘗試設置window.location.href。另外,請確保爲其分配一個字符串。這裏有一個例子:

window.location.href = "index.php"; 
+0

事實上,'window.location'讀/寫。你正在考慮'document.location'。 (即使如此,只能在IE中閱讀) – Samsquanch

0

試試這個

if ($('form #response').hasClass('success')) { 
    setTimeout(function() { 
     $('form #response').fadeOut('fast'); 
    }, 5000); 
    return window.location = 'index.php'; 
}//END IF 

還要確保它被包裹在$(function() { });