我希望第二次点击功能延迟500ms,我应该在哪里插入这个?
$(document).ready(function(){
  $('.dropToggler').click(function() {
    $(this).parent().addClass("open");
  });
    $('.acceptCta').click(function() {      //I want the delay on this function.
    $(this).parent().removeClass("open");
  });
});我也试过了,不管用:
$(document).ready(function() {
  $('.dropToggler').click(function() {
    $(this).parent().addClass("open");
  });
  setTimeout(function() {
    $('.acceptCta').click(function() {
      $(this).parent().removeClass("open");
    });
  }, 800);
});发布于 2020-07-29 20:27:51
您需要委派并在单击时告知您引用的是哪个元素,并将其用于setTimeout - removeClass函数
var $this = $(this) //将被点击函数
当我们搜索clicked事件元素的父元素时,setTimeout(function() {}并不知道什么是$(this)。
$(document).ready(function() {
  $('.dropToggler').click(function() {
    $(this).parent().addClass("open");
  });
    $('.acceptCta').click(function() { 
     //This needed
      var $this = $(this)
      //delay removeClass
      setTimeout(function() {
        $this.parent().removeClass("open");
      }, 800);
    });
});发布于 2020-07-29 20:10:51
setTimeout(function(){ 
    //your code goes here
   alert("Hello"); 
}, 3000);//here you can set the time in milliseconds
您可以使用setTimeout Function
https://stackoverflow.com/questions/63153269
复制相似问题