How to use JS to make the text in HTML not selectable? The first way to think about this is to use a CSS selector, as follows:
-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;- Ms-user-select:none;user-select:none;
However, this is not compatible with the old browser, so this article will discuss how to use JS to implement, and compatible with all browsers.
The first thing to think about is:
<!doctype html>
This makes it possible to complete HTML text without the option, and if you are using jquery you can also extend the jquery plugin in a way that implements:
<!doctype html>
Or:(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 ();});
OK, so you can basically be compatible with all browsers.