简体   繁体   中英

Textarea highlight on focus

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>

Fiddle: http://jsfiddle.net/spedwards/Mr2ja/

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>

FIDDLE

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM