角JS触发blur事件 [英] Angular js trigger blur event

查看:309
本文介绍了角JS触发blur事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装一个输入,例如,当长度== 5时,会自动触发blur事件。我怎样才能做到这一点?

I'm trying to setup an input, such that when length == 5, it will automatically trigger a blur event. How can I do this?

这是pretty太多的概念:

This is pretty much the concept:

        <input type="tel" placeholder="type here." maxlength="5" name="digits" ng-model="digits" ng-change="if (digits.length ==5) { TRIGGER BLUR};">

感谢

推荐答案

下面是一个基本的指令,应该得到你在找什么:

Here is a basic directive that should get you what you are looking for:

app.directive('lengthChecker', function() {
  return function(scope, element, attributes) {
    scope.$watch(attributes.lengthChecker, function(newVal, oldVal) {
      if (newVal.length >= 5) element[0].blur();
    });
  };
});

HTML:

<input ng-model="digits" length-checker="digits"/>

这篇关于角JS触发blur事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆