为了账号安全,请及时绑定邮箱和手机立即绑定

设置第二次点击功能jQuery的延迟

设置第二次点击功能jQuery的延迟

一只甜甜圈 2022-12-09 17:05:37
我想让第二次点击功能延迟 500 毫秒,我应该在哪里插入这个?$(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);});
查看完整描述

2 回答

?
侃侃尔雅

TA贡献1801条经验 获得超15个赞

您需要委托并告诉您在单击时指的是哪个元素并将其用于setTimeout-removeClass功能


var $this = $(this)// 将是点击函数


setTimeout(function() {}$(this)在我们搜索clicked事件元素的父元素时不知道是什么。


$(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);

    });

});


查看完整回答
反对 回复 2022-12-09
?
噜噜哒

TA贡献1784条经验 获得超7个赞

setTimeout(function(){ 

    //your code goes here

   alert("Hello"); 

}, 3000);//here you can set the time in milliseconds


查看完整回答
反对 回复 2022-12-09
  • 2 回答
  • 0 关注
  • 75 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信