첫째 :
흐림/포커스 변경이 중지의 영향을받지 않습니다 클릭 전파. (당신은 stopPropagation
, stopImmediatePropagation
또는 preventDefault
의 사용하여야한다 - 단지 클릭의 기본 동작하지 않습니다) 반면에
을 :
이전에 초점을 가지고 어떤 요소에 초점을 유지하려는 경우 다음을 수행해야합니다
- 하는 것은 선택 한 경우에 초점을 복원 선택
- 와의 상호 작용을 시작할 때 포커스를 가지고있는 기억
예제 : http://jsfiddle.net/LZQSC/3/
$("#testInput").blur(function(){console.log('blur');});
(function(){
// stores focused element reference
var focusedElement;
$('#testDropdown').on('mousedown', function(e){
// on mousedown we get the focused element
var el = $(':focus');
// if this is other than the current select element
if(el.length > 0 && el[0] !== e.currentTarget){
// save it in the var
focusedElement = el;
}
}).change(function(e){
console.log('changed');
/* do stuff */
// restore original focus
console.log('setting focus on'+focusedElement.selector);
focusedElement.focus();
});
})();