Home  >  Article  >  Web Front-end  >  How to use onselectstart and onselect

How to use onselectstart and onselect

一个新手
一个新手Original
2017-10-09 09:47:373082browse

1.onselectstart

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


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

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>

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!

Statement:
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