onClick在5秒后重定向到一侧

onClick redirect to a side after 5 sec

本文关键字:重定向 5秒 onClick      更新时间:2023-09-26

我该如何添加到按钮中,以便在我按下按钮后,它会在大约5秒后将我重定向到一侧?我尝试了很多不同的东西,但对我不起作用。。。它需要是一个onClick函数(javascript)。

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寻求帮助!

这应该会将您重定向到另一个站点:

window.location="http://www.yoururl.com";

您基本上可以创建一个setInterval(代码,毫秒)为5000的函数。并将该代码替换为u所具有的函数。

<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> 

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

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

演示

购买前试用