支持该事件的 JavaScript 对象:
button, checkbox, fileUpload, layer, frame, password, radio, reset, select, submit, text, textarea, window
实例
在本例中,当输入框获得焦点时,其背景颜色将改变:
<html> <head> <script type="text/javascript"> function setStyle(x) { document.getElementById(x).style.background="yellow" } </script> </head> <body> First name: <input type="text"onfocus="setStyle(this.id)" id="fname"
/> <br /> Last name: <input type="text"onfocus="setStyle(this.id)" id="lname"
/> </body> </html>