jQuery.fn这是窗口,并导致错误

时间:2019-03-02 04:15:22

标签: javascript jquery events mobile

我正在尝试提供一种更好的移动方式来在jQuery中dblclick,但是我一直在遇到错误,this.each is not a function一直存在。另外,这是全局窗口对象,而不是

`jQuery.fn.dblclick =(回调)=> {         var touchtime;         console.log({this:this});

    return this.each(()=>{
        $(this).on("click", function (e) {
            if (touchtime == 0) {
                touchtime = new Date().getTime();
            } else {
                if (((new Date().getTime()) - touchtime) < 800) {
                    callback(e);
                    touchtime = 0;
                } else {
                    touchtime = new Date().getTime();
                }
            }
        });
    });
};
// a few lines later...
$('button').dblclick((e)=>{...})`

这是一个jsfiddle:click here

0 个答案:

没有答案