正则表达式 – 带有ng-pattern的Angularjs ui-mask
发布时间:2020-12-14 06:07:30 所属栏目:百科 来源:网络整理
导读:下面的代码不起作用.. input type="text" class="form-control input-sm" placeholder="hh:mm:ss" name="hhmmss" ng-model="data.hhmmss" ui-mask="99:99:99" ng-pattern="/^([0-2]|0[0-9]|1[0-9]|2[0-3]):?[0-5][0-9]:?[0-5][0-9]$/"/ 当输入值为20:00:00时
下面的代码不起作用..
<input type="text" class="form-control input-sm" placeholder="hh:mm:ss" name="hhmmss" ng-model="data.hhmmss" ui-mask="99:99:99" ng-pattern="/^([0-2]|0[0-9]|1[0-9]|2[0-3]):?[0-5][0-9]:?[0-5][0-9]$/" /> 当输入值为20:00:00时,则为formName.hhmmss.$error.pattern为true. 如果删除ui-mask: <input type="text" class="form-control input-sm" placeholder="hh:mm:ss" name="hhmmss" ng-model="data.hhmmss" ng-pattern="/^([0-2]|0[0-9]|1[0-9]|2[0-3]):?[0-5][0-9]:?[0-5][0-9]$/" /> 当输入值为20:00:00时,则为formName.hhmmss.$error.pattern为false. 如何在ng-pattern中使用正则表达式? 解决方法
我遇到了同样的问题并更改了mask.js文件以更新keypress上的范围值.有一行代码执行此操作但不会一直运行.
controller.$setViewValue(valUnmasked); 将if语句更新为以下内容: if (valAltered || iAttrs.ngPattern) { 这将在keypress上运行“scope.apply”并更新模型. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |