简体   繁体   中英

highlight and select a text of a input with jQuery

I cannot find a solution in stackoverflow. I have an input filed and a value. I want the value to be selected and highlighted, so the user can easily copy the text. How can I do it with jQuery?

<input value="copy this text easily"  />

使用jQuery,您可以使用select函数:

$("input").select();

Try

$('input').focus()

Check Fiddle

You may need to change the selector though. I wrote a generic selector since there in only 1 input in the example.

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