Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用angular.js在caps lock打开/关闭时检测_Javascript_Angularjs_Capslock - Fatal编程技术网

Javascript 如何使用angular.js在caps lock打开/关闭时检测

Javascript 如何使用angular.js在caps lock打开/关闭时检测,javascript,angularjs,capslock,Javascript,Angularjs,Capslock,我需要一个帮助。我有一个密码字段验证,只需要特殊字符。在键入密码时,如果用户键入任何大写字母,则会显示大写锁定通知,当它关闭时,也会显示消息。请检查下面我的现有代码 <span class="input-group-addon ndrftextwidth text-right" style="width:180px">Password :</span> <div ng-class="{ 'has-error': billdata.pass.$touched &

我需要一个帮助。我有一个密码字段验证,只需要特殊字符。在键入密码时,如果用户键入任何大写字母,则会显示大写锁定通知,当它关闭时,也会显示消息。请检查下面我的现有代码

<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Password :</span>
<div ng-class="{ 'has-error': billdata.pass.$touched && billdata.pass.$invalid }">
<input type="{{inputType}}" name="pass" id="contactno" class="form-control" placeholder="password" ng-model="password" ng-minlength="8" ng-pattern="/^(?=.*[A-Z])(?=.*\d)(?=.*[a-z]).*_.*/" >
</div>
</div>
<div class="help-block" ng-messages="billdata.pass.$error" ng-if="billdata.pass.$touched">
<p ng-message="minlength" style="color:#F00;">This field is too short.The min length of your password should be 8.</p>
<p ng-message="pattern" style="color:#F00;">This field needs the special character like at least one number,upper case,lower case letter and underscore.</p>

</div>
密码:
此字段太短。密码的最小长度应为8

此字段至少需要一个数字、大写字母、小写字母和下划线等特殊字符


请帮助我解决此问题。

这可以使用
ngCapsLock
模块完成

包括relevent js并将ngCapsLock指定为依赖项:

angular.module('myApp', ['ngCapsLock']);
然后

caps lock已启用


支持capslock的简单库

使用CapsLock.js

caps lock钥匙的当前状态可以使用isOn功能确定,如果caps lock当前显示为打开,则返回true;如果caps lock当前显示为关闭,则返回false:

// check the state of the caps lock key
if (CapsLock.isOn()){

  // caps lock is on

}

对于angularJS开发人员,下面是一个检查按钮是否激活的工作示例:

在您的JS文件上:

  $scope.checkCase = function(event) {
        var isOn = event.originalEvent.getModifierState('CapsLock');
        if (isOn) {
            console.log('ON');
        }
    };
HTML:将其添加到您的输入中:

 ng-keyup="checkCase($event)"

我正在使用,但没有收到任何消息。您确定已正确包含文件和指定的依赖项吗?我尚未发布全部代码。让我创建plunkr。您可以检查。
 ng-keyup="checkCase($event)"