角度按键干扰形式输入

时间:2017-05-30 03:13:39

标签: angularjs

当输入字段具有焦点时,我不希望触发该函数(请参阅jsfiddle)

myApp.directive('keypressEvents', ["$document", "$rootScope", function ($document, $rootScope) {
function link($scope, $element, $attrs) {
    //console.log($document, $element, $scope, $attrs);
    $document.bind('keypress', function (e) {
        //console.log(e.key);
        var key = String.fromCharCode(e.which);
        if (key == 1 || key == 2 || key == 3) {
            //alert(key);
            $rootScope.$broadcast('keypress', e, e.which);
        }
    });
}

return {
    link: link
};
}]);

https://jsfiddle.net/28cm90v9/

如果文本输入字段有焦点,有没有办法设置If()条件?

1 个答案:

答案 0 :(得分:0)

在需要数字的表单字段

上使用这些
ng-blur="blurred()" ng-focus="focused()"