Home > Web Front-end > JS Tutorial > Javascript implementation code to cancel text selection_javascript skills

Javascript implementation code to cancel text selection_javascript skills

WBOY
Release: 2016-05-16 18:16:36
Original
1354 people have browsed it

Cancel selected text in javascript, now compatible with all major browsers:

Copy code The code is as follows:

if (document.selection) {
document.selection.empty();
} else if (window.getSelection) {
window.getSelection().removeAllRanges();
}

For unselecting the text in the text box (input, textarea), this method will have some problems.

But there is also a way, record the value in the text box, and then Clear it and reassign it. The method is a bit confusing, but it is compatible with all browsers.
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template