Home >Web Front-end >JS Tutorial >How to use onselectstart and onselect
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 = 'text' id = 'input> <script> var input = document.getElementById('input'); 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!