首先:
停止点击传播不会影响模糊/焦点变化。(你应该使用任何一个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();
});
})();