javascript - $dirty 设置焦点值

标签 javascript angularjs

我正在 AngularJS 中创建一个表单,我想验证这些字段,问题是只有在输入中写了一些东西并且在我删除它之后才会出现所需的消息,但我希望消息出现在聚焦输入之后

我的代码如下

<input type="text" name="textInput" data-ng-model="field.data"  class="form-control" required/>
<span  ng-show="form.textInput.$dirty && form.textInput.$error.required">Required!</span>

最佳答案

尝试以下操作

<span  ng-show="form.textInput.$touched && form.textInput.$error.required">Required!</span>

这将在您触摸并离开(失去焦点)且字段无效后显示消息。 Documentation

关于javascript - $dirty 设置焦点值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33811928/

相关文章:

javascript - 使用jquery获取URL内容

javascript - 使用 Angular 更改单元格的背景颜色

css - Angular-snap 不能与 ngSticky 一起使用

javascript - 过滤此正则表达式中的字符

javascript - 如何以编程方式单击选择元素并触发 onChange 处理程序?

javascript - 复选框在 Accordion 的 ng-repeat 中被禁用

c# - AngularJS 路由问题

javascript - 使用angularjs在特定页面加载外部库

javascript - 如何更改 Alfresco 共享表单中突出显示的元素颜色

javascript - Lodash:差异函数,但基于 JSON 格式