Javascript:如何通过触摸选择文本并防止拖动屏幕

问题描述

enter image description here

在桌面上我有 mousedown 和 mouseup,当我有 mouseup 时,我也使用 windows.GetSelection() - 这里没问题!

但是为了在移动设备上做同样的事情,我必须使用四个触摸事件:

touchstart,touchend,touchmove,touchcancel

我必须防止触摸屏拖动 - 可能使用 e.preventDefault代码看起来如何?

代码摘录:

$("body").on("mousedown touchstart",".redBox",async function (e) { [...] });

$("body").on("mouseup touchend","p.redBox",function(e) {

    this.addEventListener("mouseleave",() => {
        document.removeEventListener("selectionchange",logSelection);          
    })
   
    
    });
      if (this.innerHTML != "") {
        selectTextFromWindow(e);
    }
    
});

function selectTextFromWindow(event) {
    
    var selectionObject = window.getSelection();

    [...]      

    }       

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)