Is there a way to use event.preventDefault with focusOut? If not, why?

前端 未结 4 1260
慢半拍i
慢半拍i 2021-02-07 07:18

I would like to prevent the default event from a focusOut (or blur) event and keep the focus set to the specific input field.

This is what I ha

4条回答
  •  清歌不尽
    2021-02-07 07:32

    We know that it is the click function that cause the issue. So in the normal explorer like chrome, you can detact the mousedown event and then preventDefault.

    But this doesn't work in ie, but we can use the beforedeactivate event instead http://msdn.microsoft.com/en-us/library/windows/apps/jj569321.aspx. It can be deteact in ie when the focus is changing. so just prevent it.

    code would like this:

           $inp.on('blur', function(){
    
                self.hide();
            });
    
            isIE && $inp.on('beforedeactivate', function(evt){
                mousedown && evt.preventDefault();
            });
    
            $holder.on('mousedown', function(evt){
                evt.preventDefault();
                mousedown = 1;
            });
    

提交回复
热议问题