Javascript 3 秒后移除课程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26409629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove class after 3 seconds
提问by Lucas Haas
I'd like to put a timeout function to remove these two classes, but I have no idea how to do that. Can anyone help me how to include a timeout here? Thanks in advance.
我想放置一个超时函数来删除这两个类,但我不知道该怎么做。任何人都可以帮助我如何在此处包含超时?提前致谢。
.done(function(response) {
// Make sure that the formMessages div has the 'success' class.
$(formMessages).removeClass('error');
$(formMessages).addClass('success');
// Set the message text.
$(formMessages).text('Message sent!');
// Clear the form.
$('#name').val('');
$('#email').val('');
$('#message').val('');
//$('#budget').val('');
})
回答by prawn
maybe something like...
也许像……
setTimeout(function(){
$(formMessages).removeClass('error');
//....and whatever else you need to do
}, 3000);
回答by giordanolima
Using jquery...:
使用 jquery...:
$(formMessages)
.delay(3000) // its like settimeout
.removeClass('error');
Reference: http://api.jquery.com/delay/
回答by Rizo
Using Angular js you can use time function like this:
使用 Angular js,您可以像这样使用时间函数:
setTimeout(function(){
var myE2 = angular.element( document.querySelector( '#compaignhiglighted' ) );
myE2.removeClass('compaignhiglighted');
}, 3000);
回答by Aditya Kapoor
Use queuemethod (https://api.jquery.com/queue/) to queue your function calls in combination with delay.
使用queue方法 ( https://api.jquery.com/queue/) 将您的函数调用与delay.
$(formMessages)
.addClass('error')
.delay(3000)
.queue(function(next){
$(this).removeClass('error');
next();
})

