菜单切换
FACESOHO知行者
心灵
记录
远方
赞赏工具
源代码:
点击运行
保存
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>小鸟启蒙(facesoho.com)</title> </head> <body> <p>该实例演示了如何使用 HTML DOM 向 input 元素添加 "onfocusin" 事件。</p> 输入您的名字: <input type="text" id="fname"> <p><strong>注意:</strong> Firefox 浏览器不支持 onfocusin 事件。</p> <p><strong>注意:</strong> 该实例可能无法在 Chrome, Safari 和 Opera 15+ 中工作。</p> <script> document.getElementById("fname").onfocusin = function() {myFunction()}; function myFunction() { document.getElementById("fname").style.backgroundColor = "red"; } </script> </body> </html>
运行结果