如何使用js让html中的文本不可选呢?首先想到的方法是使用css选择器来实现,如下:
-webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
首先想到的是:
(function ($) { $.fn.disableSelection = function () { return this.each(function () { if (typeof this.onselectstart != 'undefined') { this.Onselectstart= function() { return false; }; } else if (typeof this.style.MozUserSelect != 'undefined') { this.style.MozUserSelect = 'none'; } else { this.Onmousedown= function() { return false; }; } }); }; })(jQuery); $(document).ready(function() { $('label').disableSelection(); // Or to make everything unselectable $('*').disableSelection(); });