开发者

hide a message after 30 seconds.?

How can a开发者_JAVA百科fter click on button show a message and next hide it after 30 seconds?

Like:

$('#message').live('click', function() {
    $('#sm').hide();
    $('#sm').hide().show('slow').html('You have successfully registered');
    // how is hide "$('#sm')" after 30 seconds??
});

Please give me example in http://jsfiddle.net/


$('#message').live('click', function() {
    $('#sm').hide().show('slow').html('You have successfully registered');
    setTimeout(function(){ $('#sm').hide(); }, 30000);
});

JSFiddle Example


setTimeout(function() {
    $('#sm').hide();
}, 30000);


in your third line you write:

$('#sm').hide().show('slow').html('You have successfully registered').delay(30000).hide();

hope it works


You are looking for setTimeout it takes a function and milliseconds as parameter. In your case it would be something like:

setTimeout(function() { $('#sm').hide() ; }, 30000);


Use either javascript's native setTimeout function or jQuery's delay function. If you choose the latter all you have to do is add:

.delay(30000).hide();

at the end of your existing code like so:

$('#sm').hide().show('slow').html('You have successfully registered').delay(30000).fadeOut();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜