Jquery:添加class后延迟删除class Delay Removing a Class in Jquery

错误实例:

$("#div").addClass("error").delay(1000).removeClass("error");

一般有三种解决方法:

1. You can use setTimeout() function:

$(document).ready(function () {
   var $rows = $("#rowone.one, #rowtwo.three, #rowthree.two").addClass("pageLoad");

   setTimeout(function() {
       $rows.removeClass("pageLoad");
   }, 1000);
});

2. You can create a new queue item to do your removing of the class:

$("#div").addClass("error").delay(1000).queue(function(next){
    $(this).removeClass("error");
    next();
});

3. 同上,不同写法:

$("#div").addClass("error").delay(1000).queue(function(){
    $(this).removeClass("error").dequeue();
});

 

个人喜好第三个方法!

 

本文:Jquery:添加class后延迟删除class Delay Removing a Class in Jquery

Loading

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.