onfocus - 当输入字段获得焦点时
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function myFunction(x) {
- x.style.background = "yellow";
- }
- </script>
- </head>
- <body>
- 请输入您的姓名:<input type="text" onfocus="myFunction(this)">
- <p>当输入字段获得焦点时,将触发一个更改背景颜色的函数。</p>
- </body>
- </html>