一只甜甜圈
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條經驗 獲得超16個贊
您需要委托并告訴您在單擊時指的是哪個元素并將其用于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);
});
});

嚕嚕噠
TA貢獻1784條經驗 獲得超7個贊
setTimeout(function(){
//your code goes here
alert("Hello");
}, 3000);//here you can set the time in milliseconds
添加回答
舉報
0/150
提交
取消