Home > Article > Web Front-end > JavaScript method to get selected text in text box_javascript skills
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:
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.