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

前端 未结 7 2070

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条回答
  •  情话喂你
    2020-12-28 16:21

    Looks like an oddity of angularjs gives a simpler solution when using ng-blur; the $event object is only defined if you pass it in:

    ng-blur="onBlur($event)"
    

    so (if you aren't using ng-blur on the window) you can check for:

    $scope.onBlur = function( $event ) {
        if (event != undefined) {
           //this is the blur on the element
        }
    }
    

提交回复
热议问题