javascript – Jquery – 双击时遇到麻烦,因为课堂上有变化

前端之家收集整理的这篇文章主要介绍了javascript – Jquery – 双击时遇到麻烦,因为课堂上有变化前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个按钮. onclick我正在更改该按钮的类,但是当我双击它的更改类时.我的所有功能都取决于当前的课程
如何禁用双击或在第一次单击时完成请求.
function data() {
    lastScrollTop = 0;
    document.getElementById("expand-dataset-btn").disabled = false;
    var id = event.target.id
    var allChildern = null
    if(!$(".id_"+event.target.id).hasClass('minus-symbol')){
        $(".id_"+event.target.id).removeClass('plus-symbol').addClass('minus-symbol')
        $.ajax({

            },success : function(result) {

            }
         });
    }else{
        $(".id_"+event.target.id).addClass('plus-symbol').removeClass('minus-symbol')
        $.ajax({

            },success : function(result) {

            }
         });
    }
}

从下面的控制器调用功能

htmlDataId += "<a onclick=\"data()\" title='View' id="+row[primaryField]+">

解决方法

你需要的是“油门”功能或“去抖动”功能.

Throttling is a means by which we can limit the number of times a function can be called in a given period. For instance,we may have a method that should be called no more than 5 times per second.

你可以使用下划线underscore official website

要么

您可以使用以下代码

/*trigger specific eventhandler when the event is idle for specific time*/
function debounce(fn,delay,self) {
    var timer = null;
    return function () {
        var context = self ? self : this,args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
        fn.apply(context,args);
        },delay);
    };
}
//use in the following way
 $input.on('click',debounce(clickCallback,250));

然后如果在250ms内触发第二次“点击”事件,它将被忽略

原文链接:https://www.f2er.com/jquery/157369.html

猜你在找的jQuery相关文章