--- title: focus slug: Web/API/Element/focus_event translation_of: Web/API/Element/focus_event original_slug: Web/Events/focus ---
focus事件在元素获取焦点时触发. 这个事件和 focusin
最大的区别仅仅在于后者会事件冒泡.
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))
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()}} |