onfocus
HTML onfocus 事件属性
当输入域获得焦点时运行脚本:
<input type="text" id="fname" onfocus="setStyle(this.id)">
定义和用法
onfocus 属性在元素获得焦点时触发
Onfocus 通常用于 <input>
, <select>
, 和 <a>
元素。
提示
与 onfocus 属性相反的属性事件为onblur 。
注意
onfocus 属性不能使用于以下元素: <base>
, <bdo>
, <br>
, <head>
, <html>
, <iframe>
, <meta>
, <param>
, <script>
, <style>
, 或 <title>
。
HTML 4.01 与 HTML5之间的差异
无。
语法
<*element* onfocus="*script*">
属性值
值 | 描述 |
---|---|
script | 规定该 onfocus 事件触发时执行的脚本 |
浏览器兼容性
focus event |
---|