Angularjs 输入字段焦点事件? [英] Angularjs input field focus event?

查看:33
本文介绍了Angularjs 输入字段焦点事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 angularjs 并创建了一个像这样的普通输入字段:

i use angularjs and i have created a normal input field like this:

<input type="text" style="border: none" ng-model="model" >

我想做以下事情:

如果有人点击输入字段,我想调用例如方法A.然后他在这个字段中写入文本,如果这个人点击我页面中的某个地方,输入字段不再聚焦,它应该调用方法B.这可能与 angularjs 吗?如果是,我该怎么做?ng-focus 仅在输入事件时有效,而在输出时无效..

if someone clicks in the input field, i want call for example method A. Then he writes text in this field and if the person clicks somewhere in my page so that the input field is no longer focused it should call method B. is this possible with angularjs ? if yes, how can i do that ? ng-focus is only active at the input event but not at the output..

我想用这个锁定一些东西,方法 A 只将一个值设置为 true,方法 B 将相同的值设置为 false.但我必须知道输入字段何时处于活动状态,何时不处于活动状态.

i want lock something with this, method A sets only a value to true and method B sets the same value to false. but i must know when the input field is active and when not.

推荐答案

您正在查看 ng-focusng-blur.

You are looking at ng-focus and ng-blur.

<input type="text" style="border: none" ng-model="model" ng-focus="A()" ng-blur="B()">

附带说明,使用 css 类而不是内联样式.. :)

On a side note, use css classes instead of inline styles.. :)

或者只是使用参数调用相同的方法并设置值acc:-

Or just call the same method with argument and set the value acc:-

 <input type="text" style="border: none" ng-model="model" ng-focus="A(true)" ng-blur="A(false)">

这篇关于Angularjs 输入字段焦点事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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