gpt4 book ai didi

javascript - $dirty 设置焦点值

转载 作者:行者123 更新时间:2023-11-30 12:10:57 26 4
gpt4 key购买 nike

我正在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com