移動端長按禁止預設事件總結
阿新 • • 發佈:2018-11-03
1、如果是禁用長按選擇文字功能,用 css
:
全域性* 或者 區域性選擇相映的DOM加
* {
-webkit-touch-callout:none;
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}
但是包含input框時會導致不可用,可以新增下面程式碼:
input{
-webkit-user-select: auto;
}
2、如果對圖片禁止選中:
img { pointer-events: none; }
3、如果是想禁用長長長長按彈出選單, 用 js
:
box.addEventListener('contextmenu', function(e){
e.preventDefault();
});
4、如果需要禁止的頁面沒有點選事件,這個會導致短點選事件無效, 可以使用下面這段程式碼:
window.ontouchstart = function (e) {
e.preventDefault();
};