Jquery触摸事件适用不是一个功能

时间:2017-11-24 09:08:20

标签: javascript jquery

我有一张桌子,我可以拖放。为了能够拖放并在不拖放的情况下滚动页面,我应用了Jquery Touch。

问题是当我在表格中制作一个标签时,它在控制台中显示错误。

这是错误

jquery.js:4737 Uncaught TypeError: ((jQuery.event.special[handleObj.origType] || {}).handle || handleObj.handler).apply is not a function
at HTMLTableElement.dispatch (jquery.js:4737)
at triggerCustomEvent (jquery.mobile-events.js:846)
at HTMLTableElement.tapFunc2 (jquery.mobile-events.js:498)
at HTMLTableElement.dispatch (jquery.js:4737)
at HTMLTableElement.elemData.handle (jquery.js:4549)

代码是这样的:

$('.touchtable').tap('tap', function(e) { 
   console.log('hola2');
});

如何解决错误?

我读到的关于jquery-touch的信息在这里

https://github.com/benmajor/jQuery-Touch-Events

拖放代码

if ($('.touchtable').on('doubletap',function(e){

$("#tbodyproject").sortable({

    items: "> tr",
    appendTo: "parent",
    helper: "clone",
    placeholder: "placeholder-style",
    containment: ".table",
    start: function(event, ui) {

        var cantidad_real = $('.table thead tr th:visible').length;
        var cantidad_actual = $(this).find('.placeholder-style td').length;

          if(cantidad_actual > cantidad_real){
          var cantidad_a_ocultar = (cantidad_actual - cantidad_real);

          for(var i = 0; i <= cantidad_a_ocultar; i++){
              $(this).find('.placeholder-style td:nth-child('+ i +')').addClass('hidden-td');
          }
        }

        ui.helper.css('display', 'table')
    },
    stop: function(event, ui) {
        ui.item.css('display', '')
    },
    update: function( event, ui ) { 
        let newOrder = $(this).sortable('toArray');
        $.ajax({
            type: "POST",
            url:'/admin/projects/updateOrder',
            data: {ids: newOrder}
        })
       .done(function( msg ) {
        location.reload();        
       });
    }
}).disableSelection();

}));

2 个答案:

答案 0 :(得分:1)

您应该使用on方法而不是tap方法,并在tap方法上传递on参数,该方法会将您称为tap方法。

$('.touchtable').on('tap', function(e) { 
   console.log('hola2');
});

另一方面,您可以直接调用tap方法,如下所示:

$('.touchtable').tap(function(e) {
   console.log('hola2');
});

注意:第一种方法是事件委托方法,第二种方法是直接方法。如果您已动态插入元素,则必须使用事件委派方法才能使其正常工作。

答案 1 :(得分:0)

代码必须是这样的:

$('.touchtable').on('doubletap', function(e) { 
    console.log('User tapped touchtable'); 
});