Edit The Code:
See Result »
Try it Yourself - ©
w3big.com
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>本教程(w3big.com)</title> </head> <body> <p>该实例使用了 addEventListener() 方法来添加 input 元素的获取焦点事件。</p> 输入您的姓名: <input type="text" id="fname"> <script> document.getElementById("fname").addEventListener("focus", myFunction); function myFunction() { document.getElementById("fname").style.backgroundColor = "red"; } </script> </body> </html>