编辑下面的代码:【加编码】
<html> <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>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂