简体   繁体   English

如何禁用MobileSafari自动选择?

[英]how to disable MobileSafari auto-selection?

my webapp requires users to tap and hold on an element for a game action, 我的webapp要求用户点击并按住元素进行游戏操作,
but iPhone automatically "selects" the area which is confusing to the user. 但iPhone会自动“选择”让用户感到困惑的区域。

anyone know what html elements prevent selection, or if javascript can block selection? 有谁知道什么html元素阻止选择,或者javascript可以阻止选择?

any help is appreciated 任何帮助表示赞赏

Try handling the selectstart event and returning false . 尝试处理selectstart事件并返回false

Try applying the CSS rule, -webkit-user-select: none; 尝试应用CSS规则, -webkit-user-select: none;

SLaks answer is obviously right - I just want to extend it a bit for future viewers. SLaks答案显然是正确的 - 我只是想为未来的观众扩展一点。 If you're using jQuery, here's a useful extension method that disables selection in various browsers: 如果您正在使用jQuery,这是一个有用的扩展方法,禁用各种浏览器中的选择:

$.fn.extend({ 
        disableSelection : function() { 
                this.each(function() { 
                        this.onselectstart = function() { return false; }; 
                        this.unselectable = "on"; 
                        $(this).css('-moz-user-select', 'none'); 
                        $(this).css('-webkit-user-select', 'none'); 
                }); 
        } 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM