搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
JavaScript 教程
JavaScript基础教程
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>JavaScript onfocus 事件示例 - 基础教程(div.cn)</title> <body> <h1>HTML onfocus 事件</h1> <input type="text" onfocus="func1(this)" onblur="func2(this)"> <script> function func1(x) { x.style.background = 'lightgreen'; } function func2(x) { x.style.background = 'coral'; } </script> <p>当输入字段获得焦点时,函数func1()被触发:</p> <p>当输入字段失去焦点时会触发函数func2():</p> </body> </html>
运行结果