Chrome (maybe Safari?) fires “blur” twice on input fields when browser loses focus

前端 未结 7 2077

Here is an interesting jsfiddle.

In Firefox:

  1. Run the fiddle
  2. Click in text input
  3. Click somewhere else. Should say \"1 bl
7条回答
  •  -上瘾入骨i
    2020-12-28 16:16

    Skip 2nd blur:

    var secondBlur = false;
    this.onblur = function(){
        if(secondBlur)return;
        secondBlur = true;
        //do whatever
    }
    this.onfocus = function(){
        secondBlur = false;    
        //do whatever
    }
    

提交回复
热议问题