2013-08-30 90 views
1

如何在按下按钮后添加到按钮中。它会在5秒之后将我重定向到一侧? 我已经尝试了这么多不同的东西,但它不适合我... 它需要是一个onClick函数(javascript)。onClick 5秒后重定向到一侧

HTML:

<html> 
<head> 

<style type="text/css"> 
#save_first { display: none; } 
#save_second { display: none; } 
#save_third { display: none; } 
</style> 

<script type="text/javascript" src="http://mctheblitz.com/servers/js/jquery.js"></script> 
<script type="text/javascript" src="js/custom.js"></script> 

</head> 
<body> 

<input type="button" value="Save" onClick="save();"/> 
<div id="save_first"></div><div id="save_second"></div> 
<?php 



</body> 
</html> 

javascipt的:

function save() { 

    $('#save_first').html('Validating...'); 
    $('#save_first').fadeIn(1); 
    $('#save_first').delay(2000); 
    $('#save_first').fadeOut(300); 
    $('#save_second').html('Successfully log in!'); 
    $('#save_second').hide(); 
    $('#save_second').delay(2350); 
    $('#save_second').fadeIn(0); 
} 

TNX的帮助!

回答

0

你可以基本上用setInterval(code,millisec)创建一个函数为5000.并用你有的函数替换代码。

<html> 
<body> 

<input type="text" id="clock"> 
<script language=javascript> 

function fiveseconds() { 
    setInterval(function(){clock()},5000); 
} 


function clock() { 
    alert("pow"); 
} 
</script> 

<button onclick="fiveseconds()">Stop</button> 

</body> 
</html> 
+0

它只是一个基地。你需要在5秒设定某种块。 – Daniel

0

看起来你正在使用jQuery。你可以这样说:

$('#id-of-button').click(function() { 
    setTimeout(function() { location.href='http://url.tld'; }, 5000); 
    $(this).unbind(); 
}); 

演示

Try before buy

+0

oki所以我做了'$('#redirect')。click(function(){ setTimeout(“location.href ='index.php'”,4651); $(this).unbind(); }); '并且这个''**然后没有发生任何事情** @insetusernamehere – user2733334

+0

@ user2733334对不起,我忘了把它变成了封闭。我已经更新了答案并添加了演示。 – insertusernamehere