lov*_*ing 61 javascript jquery dom javascript-events
如果它们是相同的,那么为什么会有这样的事件呢?
Pat*_*her 63
如您所知,onBlur事件会触发一个元素,如果该元素具有焦点,但会丢失它.
该onfocusout在这种情况下事件触发,但也触发如果任何子元素失去焦点.
例如,您有一个具有特殊格式的div,因为人类当前正在编辑该区域中的字段.当焦点离开该div时,您可以使用onFocusOut关闭该格式.
直到最近,onFocusOut才被IE使用.如果情况发生了变化,那就是最近的情况.在FF,Chrome等测试
一个小演示。请注意,focusin/focusout 的父 div 更改了颜色。
div {
background-color: #eee;
padding: 5px;
}
Run Code Online (Sandbox Code Playgroud)
<div onfocusin="this.style['background-color']='#efe'"
onfocusout="this.style['background-color']='#eef'">
<input onfocusin="this.value='focusin'"
onfocusout="this.value='focusout'"
placeholder="focusin/focusout"/> bubbling (parent div receives event, too)
</div>
<div onfocus="this.style['background-color']='#efe'"
onblur="this.style['background-color']='#eef'">
<input onfocus="this.value='focus'"
onblur="this.value='blur'"
placeholder="focus/blur"/> not bubbling
</div>
Run Code Online (Sandbox Code Playgroud)