// 给密码输入框绑定判定大写锁定事件 const $this = this; const checkCapsLock = function(evt) { const capsLockKey = evt.keyCode ? evt.keyCode : evt.which; const shifKey = evt.shiftKey ? evt.shiftKey : ((capsLockKey == 16) ? true : false); if (((capsLockKey >= 65 && capsLockKey <= 90) && !shifKey) || ((capsLockKey >= 97 && capsLockKey <= 122) && shifKey)) { $this.capsLock = true; } else { $this.capsLock = false; } } const pwdInput = document.getElementById('password'); pwdInput.onkeypress = checkCapsLock; pwdInput.onblur = function() { $this.capsLock = false; }
vue中使用