--- title: focus slug: Web/API/Element/focus_event translation_of: Web/API/Element/focus_event original_slug: Web/Events/focus ---

focus事件在元素获取焦点时触发. 这个事件和 focusin 最大的区别仅仅在于后者会事件冒泡.

基本信息

规范
DOM L3
接口
{{ domxref("FocusEvent") }}
是否冒泡
能否取消默认
事件目标
Element
默认行为
无.
注释: 这里的接口是指 {{ domxref("Event") }} prior to Gecko 24 {{ geckoRelease(24) }}. ({{ bug(855741) }})

属性

Property Type Description
target {{readonlyInline}} {{domxref("EventTarget")}} Event target (DOM element)
type {{readonlyInline}} {{domxref("DOMString")}} The type of event.
bubbles {{readonlyInline}} {{jsxref("Boolean")}} Whether the event normally bubbles or not.
cancelable {{readonlyInline}} {{jsxref("Boolean")}} Whether the event is cancellable or not.
relatedTarget {{readonlyInline}} {{domxref("EventTarget")}} (DOM element) null

事件委托

此事件有两个可以实现事件委托的方法 : 通过在支持的浏览器上使用 focusin 事件 (除了Firefox之外的所有浏览器), 或者通过设置 addEventListener 的参数"useCapture" 值为true:

{{ EmbedLiveSample('Event_delegation', '', '', '', 'Web/Events/blur') }}

(Sample code from blur (event))

浏览器兼容性

{{CompatibilityTable}}
Featrue Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown()}} {{CompatVersionUnknown}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}}
Feature Android Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatUnknown()}} {{CompatUnknown()}} {{CompatVersionUnknown}} {{CompatUnknown()}} {{CompatUnknown()}} {{CompatUnknown()}} {{CompatUnknown()}}

相关事件