Javascript 使用触摸事件时,禁止关闭菜单

Javascript 使用触摸事件时,禁止关闭菜单,javascript,jquery-ui-contextmenu,Javascript,Jquery Ui Contextmenu,我已经连接了一个简单的长触摸功能,500毫秒后使用“打开”API命令打开上下文菜单。菜单打开了。但是,在“touchend”上,菜单消失。仅当我在“touchend”之前的上下文菜单上触摸Move时,它才会保持不变。有没有办法防止这种行为?从源代码来看,只有dom不同部分中的“touchstart”才会触发关闭事件 代码如下,以防有用。我的上下文菜单并不要求tr的委托-在下面解释targetTr变量的用法 var mobDevice_onLongTouch, mobDevice_touc

我已经连接了一个简单的长触摸功能,500毫秒后使用“打开”API命令打开上下文菜单。菜单打开了。但是,在“touchend”上,菜单消失。仅当我在“touchend”之前的上下文菜单上触摸Move时,它才会保持不变。有没有办法防止这种行为?从源代码来看,只有dom不同部分中的“touchstart”才会触发关闭事件

代码如下,以防有用。我的上下文菜单并不要求tr的委托-在下面解释targetTr变量的用法

var mobDevice_onLongTouch,
    mobDevice_touchTimer,
    mobDevice_longPressDuration = 500; //length of time we want the user to touch before we do something

//handle long press on the datatable
var touchArea = document.querySelector("#table");
touchArea.addEventListener("touchstart", touchAreaTouchStart, false);
touchArea.addEventListener("touchend", touchAreaTouchEnd, false);

function touchAreaTouchStart(e) {
    var targetTr = $(e.target).closest('tr');
    mobDevice_touchTimer = setTimeout(function () { touchArea_onLongTouch(targetTr) }, mobDevice_longPressDuration)
};
function touchAreaTouchEnd(e) {
    if (mobDevice_touchTimer) {
        clearTimeout(mobDevice_touchTimer) //reset the clock
    }
};

function touchArea_onLongTouch(target) {
    $('#table').contextmenu('open', target);
};

我解决了这个问题。ContextMenu工作正常,但我接触的DOM控件在touchend上注册了一个更改事件(突出显示一个表行)。因此,在touch-and-hold过程中弹出上下文菜单,然后在touchend中通过DOM更改清除

解决方案是手动将highlight table row事件添加到touchstart和preventDefault on touchend(当触摸目标位于表内时)