onblur 特性为 GlobalEventHandlers 混合 EventHandler 为处理 blur events. It's available on 元素 , Document ,和 Window .

blur event is raised when an element loses focus.

注意: The opposite of onblur is onfocus .

句法

target.onblur = functionRef;
					

functionRef is a function name or a 函数表达式 . The function receives a FocusEvent object as its sole argument.

范例

此范例使用 onblur and onfocus to change the text within an <input> 元素。

HTML

<input type="text" value="CLICK HERE">
					

JavaScript

let input = document.querySelector('input');
input.onblur = inputBlur;
input.onfocus = inputFocus;
function inputBlur() {
  input.value = 'Focus has been lost';
}
function inputFocus() {
  input.value = 'Focus is here';
}
					

结果

Try clicking in and out of the form field, and watch its contents change accordingly.

规范

规范 状态 注释
HTML 实时标准
The definition of 'onblur' in that specification.
实时标准

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
onblur Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

In contrast to IE, in which almost all kinds of elements receive the blur event, only a few kinds of elements on Gecko browsers work with this event.

另请参阅

元数据

  • 最后修改:
  1. GlobalEventHandlers
  2. 特性
    1. onabort
    2. onanimationcancel
    3. onanimationend
    4. onanimationiteration
    5. onauxclick
    6. onblur
    7. oncancel
    8. oncanplay
    9. oncanplaythrough
    10. onchange
    11. onclick
    12. onclose
    13. oncontextmenu
    14. oncuechange
    15. ondblclick
    16. ondurationchange
    17. onended
    18. onerror
    19. onfocus
    20. onformdata
    21. ongotpointercapture
    22. oninput
    23. oninvalid
    24. onkeydown
    25. onkeypress
    26. onkeyup
    27. onload
    28. onloadeddata
    29. onloadedmetadata
    30. onloadend
    31. onloadstart
    32. onlostpointercapture
    33. onmousedown
    34. onmouseenter
    35. onmouseleave
    36. onmousemove
    37. onmouseout
    38. onmouseover
    39. onmouseup
    40. onpause
    41. onplay
    42. onplaying
    43. onpointercancel
    44. onpointerdown
    45. onpointerenter
    46. onpointerleave
    47. onpointermove
    48. onpointerout
    49. onpointerover
    50. onpointerup
    51. onreset
    52. onresize
    53. onscroll
    54. onselect
    55. onselectionchange
    56. onselectstart
    57. onsubmit
    58. ontouchcancel
    59. ontouchstart
    60. ontransitioncancel
    61. ontransitionend
    62. onwheel
  3. 实现通过:
    1. Document
    2. HTMLElement
    3. SVGElement
    4. Window
    5. XULElement
  4. HTML DOM 相关页面
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. HTMLAnchorElement
    5. HTMLAreaElement
    6. HTMLAudioElement
    7. HTMLBRElement
    8. HTMLBaseElement
    9. HTMLBaseFontElement
    10. HTMLBodyElement
    11. HTMLButtonElement
    12. HTMLCanvasElement
    13. HTMLContentElement
    14. HTMLDListElement
    15. HTMLDataElement
    16. HTMLDataListElement
    17. HTMLDialogElement
    18. HTMLDivElement
    19. HTMLDocument
    20. HTMLElement
    21. HTMLEmbedElement
    22. HTMLFieldSetElement
    23. HTMLFormControlsCollection
    24. HTMLFormElement
    25. HTMLFrameSetElement
    26. HTMLHRElement
    27. HTMLHeadElement
    28. HTMLHeadingElement
    29. HTMLHtmlElement
    30. HTMLIFrameElement
    31. HTMLImageElement
    32. HTMLInputElement
    33. HTMLIsIndexElement
    34. HTMLKeygenElement
    35. HTMLLIElement
    36. HTMLLabelElement
    37. HTMLLegendElement
    38. HTMLLinkElement
    39. HTMLMapElement
    40. HTMLMediaElement
    41. HTMLMetaElement
    42. HTMLMeterElement
    43. HTMLModElement
    44. HTMLOListElement
    45. HTMLObjectElement
    46. HTMLOptGroupElement
    47. HTMLOptionElement
    48. HTMLOptionsCollection
    49. HTMLOutputElement
    50. HTMLParagraphElement
    51. HTMLParamElement
    52. HTMLPictureElement
    53. HTMLPreElement
    54. HTMLProgressElement
    55. HTMLQuoteElement
    56. HTMLScriptElement
    57. HTMLSelectElement
    58. HTMLShadowElement
    59. HTMLSourceElement
    60. HTMLSpanElement
    61. HTMLStyleElement
    62. HTMLTableCaptionElement
    63. HTMLTableCellElement
    64. HTMLTableColElement
    65. HTMLTableDataCellElement
    66. HTMLTableElement
    67. HTMLTableHeaderCellElement
    68. HTMLTableRowElement
    69. HTMLTableSectionElement
    70. HTMLTemplateElement
    71. HTMLTextAreaElement
    72. HTMLTimeElement
    73. HTMLTitleElement
    74. HTMLTrackElement
    75. HTMLUListElement
    76. HTMLUnknownElement
    77. HTMLVideoElement
    78. HashChangeEvent
    79. 历史
    80. ImageData
    81. 定位
    82. MessageChannel
    83. MessageEvent
    84. MessagePort
    85. Navigator
    86. NavigatorGeolocation
    87. NavigatorID
    88. NavigatorLanguage
    89. NavigatorOnLine
    90. NavigatorPlugins
    91. PageTransitionEvent
    92. Plugin
    93. PluginArray
    94. PopStateEvent
    95. PortCollection
    96. PromiseRejectionEvent
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers