60. Event onfocus 事件

来源:互联网 发布:网络市场具体有哪些 编辑:程序博客网 时间:2024/03/29 22:01

定义和用法
onfocus 事件在对象获得焦点时发生。
语法

onfocus="SomeJavaScriptCode"

这里写图片描述


实例在本例中,当输入框获得焦点时,其背景颜色将改变:<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>
0 0