Home > Web Front-end > JS Tutorial > body text

How to use onselectstart and onselect

一个新手
Release: 2017-10-09 09:47:37
Original
3113 people have browsed it

1.onselectstart

This event is mainly used to prohibit the selection of text in web pages. The code is:


document.onselectstart =function(){
            return false;
        }
Copy after login

In addition, ff/opera does not support this event, ff can be controlled with css: css: body { -moz-user-select: none; }. Webkit browsers can use "-khtml-user-select", and of course you can also use the onselectstart event to prevent users from selecting text within elements.

Note that this event does not support input and textarea.

2.onselect

This event is triggered after selecting the content in the textarea or input. Therefore only input and textarea tags are supported. For example:

<input type = &#39;text&#39; id = &#39;input>
<script>
             var input = document.getElementById(&#39;input&#39;);
             input.onselect = function(){
                alert("被触发");
            }     
</script>
Copy after login

The above is the detailed content of How to use onselectstart and onselect. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!