Home  >  Article  >  Web Front-end  >  JavaScript method to get selected text in text box_javascript skills

JavaScript method to get selected text in text box_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:13:201320browse

The example in this article describes how to obtain the selected text in the text box using JavaScript. Share it with everyone for your reference. The specific analysis is as follows:

The code here can be used to obtain the selection selected by the user in the text input box or textarea through the mouse.
Need to pay attention to the problem of ie.

The code is as follows:

Copy code The code is as follows:






Note: When using non-button elements to trigger the onclick event in IE, no result will be obtained. Because in IE, when a non-button element is clicked, the selection content in the entire page will be changed. This problem does not exist under Firefox and Opera. So the above (Span_onclick) will not be available under IE.

I hope this article will be helpful to everyone’s JavaScript programming design.

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