datatables添加长按事件

长按事件

$.fn.longPress = function (fn) {
    var timeout = undefined;
    var $this = this;
    for (var i = 0; i < $this.length; i++) {
        $this[i].addEventListener('touchstart', function (event) {
            timeout = setTimeout(fn, 800);  //长按时间超过800ms,则执行传入的方法
        }, false);
        $this[i].addEventListener('touchend', function (event) {
            clearTimeout(timeout);  //长按时间少于800ms,不会执行传入的方法
        }, false);
    }
}

datatables绑定事件

 $('#example tbody').longPress(function () {
            var data = otable.row(this).data();
            alert("长按事件");

 });
//移动端长按会出现浏览器特有的功能菜单,需要进行阻断 $(
"#example").bind("contextmenu", function() { return false; });
原文地址:https://www.cnblogs.com/m-bianbian/p/7485121.html