GlobalEventHandlers.onblur - Web APIs 编辑
The onblur
property of the GlobalEventHandlers
mixin is the EventHandler
for processing blur
events. It's available on Element
, Document
, and Window
.
The blur
event is raised when an element loses focus.
Note: The opposite of onblur
is onfocus
.
Syntax
target.onblur = functionRef;
Value
functionRef
is a function name or a function expression. The function receives a FocusEvent
object as its sole argument.
Example
This example uses onblur
and onfocus
to change the text within an <input>
element.
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';
}
Result
Try clicking in and out of the form field, and watch its contents change accordingly.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'onblur' in that specification. | Living Standard |
Browser compatibility
BCD tables only load in the browser
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.
See also
blur
event- Related event handler:
GlobalEventHandlers.onfocus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论