当输入字段具有焦点时,我不希望触发该函数(请参阅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()条件?
答案 0 :(得分:0)
在需要数字的表单字段
上使用这些ng-blur="blurred()" ng-focus="focused()"