Home > Web Front-end > JS Tutorial > js prohibits document element object from selecting text implementation code_javascript skills

js prohibits document element object from selecting text implementation code_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:39:50
Original
1104 people have browsed it
Copy code The code is as follows:

// Parameter obj: jquery object of the element whose text is to be disabled
// Parameter enabled: true, selectable; false, not selectable
function setSelectable(obj, enabled) {
if(enabled) {
obj.removeAttr("unselectable").removeAttr(" onselectstart").css("-moz-user-select", "").css("-webkit-user-select", "");
} else {
obj.attr("unselectable" , "on").attr("onselectstart", "return false;").css("-moz-user-select", "none").css("-webkit-user-select", "none") ;
}
}

The principle is as follows:

ie, you can set the handler function (return false;) of the event selectstart Disable selected text
Under ff and chrome, it can be controlled through css
As for the unselectable attribute, it can be seen as a supplementary means to adapt to as many browsers as possible.
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
document
From 1970-01-01 08:00:00
0
0
0
Chinese phpword document
From 1970-01-01 08:00:00
0
0
0
Can you share the Xmind document?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template