The example in this article describes the method of implementing text box selection in js. Share it with everyone for your reference. The details are as follows:
This javascript code can solve the problem that the text box gets focus, that is, the content of the text box is selected.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>select文件</title> <script language="javascript" type="text/javascript"> function getFocus() { document.getElementById("test").select(); } </script> </head> <body> <form id="f1"> <input type="text" id="test" name="test" value="你好嗎?" onfocus="getFocus();"/> </form> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.