I'm trying to have all the contents in a textarea highlight when it gains focus. Currently, as soon as it gains focus the contents will be highlighted but it immediately loses it.
This is what I'm using:
<textarea onfocus="this.select()" readonly>Test</textarea>
You have prevent the mouseup event as well, as it fires after the focus is set and deselects the contents
<textarea onfocus="this.select()" onmouseup="return false;" readonly="readonly">Test</textarea>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.