onfocus 事件在对象获得焦点时发生。

来源:互联网 发布:三级分销裂变公式算法 编辑:程序博客网 时间:2024/06/05 04:15

支持该事件的 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>
原创粉丝点击