在页面中样式中加上下面的css代码
*{-webkit-overflow-scrolling: touch
-webkit-touch-callout:none
-webkit-user-select:none
-khtml-user-select:none
-moz-user-select:none
-ms-user-select:none
user-select:none
}
<td id="mytd"></td><script type="text/javascript">
var tddom= document.getElementById('mytd')
var timer = null
tddom.onmousedown = function(){
timer = setTimeout( doStuff, 2000 )//这里设置时间
}
tddom.onmouseup = function(){
clearTimeout( timer )
}
function doStuff() {
alert('hello, you just pressed the td for two seconds.')
}
</script>
禁止复制οncοntextmenu='return false' //禁止右键
οndragstart='return false' //禁止拖动
onselectstart ='return false' //禁止选中
οnselect='document.selection.empty()' //禁止选中
οncοpy='document.selection.empty()' //禁止复制
onbeforecopy='return false' // 禁止复制
οnmοuseup='document.selection.empty()'
*{
moz-user-select: -moz-none
-moz-user-select: none
-o-user-select:none
-khtml-user-select:none
-webkit-user-select:none
-ms-user-select:none
user-select:none
}
长按事件document.addEventListener("touchstart", function (e) { console.log('touchstart') timer = setTimeout(function () { console.log('LongPress') e.preventDefault() LongPress(parentObj) }, 800) }) document.addEventListener("touchmove", function (e) { console.log('touchmove') clearTimeout(timer) timer = 0 }) document.addEventListener("touchend", function (e) { console.log('touchend') clearTimeout(timer) if (timer != 0) { alert('这是点击,不是长按') } return false })欢迎分享,转载请注明来源:内存溢出
评论列表(0条)