「jQuery入門」focus()メソットでテキストエリア(textarea)の文字列を選択するサンプル
書式
$('セレクタ名’).focus(function() {
$(this).select();
})
使用例
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>focus()とselect()のサンプル</title> <script src="https://code.jquery.com/jquery-3.5.0.js"></script> </head> <body> <textarea id="cft" rows="10" cols="20"> A001 B002 C003 D004 E005 </textarea> <script> $('#cft').focus(function() { $(this).select(); }) </script> </body> </html>