2013-08-16 156 views
0

我有这样的代码添加延迟()

<script type="text/javascript"> 
    var currentBlock; 

    function onSuccessEditUser(result) { 
     showMessage(result.Message); 
     window.location = '@Url.Action("UserIndex")'; 
    } 
</script> 

,我想showMessage后window.location的前加少许延迟。
我该怎么做?

回答

4

可以使用setTimeout指定的时间间隔后关火码:

function onSuccessEditUser(result) { 
    showMessage(result.Message); 

    // Wait 1 second 
    setTimeout(function() { 
     window.location = '@Url.Action("UserIndex")'; 
    },1000); 
} 
+0

非常感谢,现在有用! – Heidel

1

使用Java脚本setTimeOut方法来执行规定后一些时间

<script type="text/javascript"> 
var currentBlock;  
function onSuccessEditUser(result) { 
showMessage(result.Message); 
// Wait 5 second 
setTimeout(function() { 
    window.location = '@Url.Action("UserIndex")'; 
},5000); 
} 
<script> 
1

你可以使用一个setTimeout(function(){showMessage(result.Message);});功能。 或者选择jQuery $(..).delay(300);http://api.jquery.com/delay/ 无论你喜欢什么。

+0

'延迟()'不起作用,我试过了。 – Heidel