Angular.js: Set CSS when Input is on Focus

前端 未结 3 1926
臣服心动
臣服心动 2020-12-19 02:52

Does someone knows how to get the following working:

If an user clicks inside \"name\" - Set CSS Class to XYZ on DIV ?

E
3条回答
  •  独厮守ぢ
    2020-12-19 03:21

    Working example for pre-1.2.xxx versions: http://jsfiddle.net/atXAC/

    In this example, the ng-customblur directive will fire a function() in your controller.

    HTML:

    Enter your Name here

    JS:

    myApp.directive('ngCustomblur', ['$parse', function($parse) {
      return function(scope, element, attr) {
        var fn = $parse(attr['ngCustomblur']);      
        element.bind('blur', function(event) {        
          scope.$apply(function() {
            fn(scope, {$event:event});
          });
        });
      }
    }]);
    
    function MyCtrl($scope) {
        $scope.onBlur = function(){        
            $scope.hasFocus = false;
        }
    } 
    

提交回复
热议问题