JavaScript cursor focus event (onfocus)
Cursor focus event (onfocus)
When the object in the web page obtains the focus point, the program that executes the onfocus call will be executed.
The following code, when the cursor is moved into the text box, that is, the focus is in the text box, the onfocus event is triggered and the function fun() is called.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> function fun(){ window.alert("请输入真实姓名") } </script> </head> <body> <form> 姓名: <input name="username" type="text" value="请输入姓名" onfocus="fun()" > </form> </body> </html>