简体   繁体   English

CAPS锁定弹出窗口

[英]CAPS lock popover

I am trying to show a popover when the CAPS lock key is on during typing password, the code is working fine, the popover is displayed when CAPS is on and is hidden when it is not. 我试图在输入密码时打开CAPS锁定键时显示一个弹出窗口,代码工作正常,打开CAPS时显示弹出窗口,而没有打开时隐藏。 But I'm also getting the popover when I click on the password field, even if the caps is not on. 但是,即使没有打开大写字母,单击密码字段时也会弹出弹出窗口。

I need some help with this. 我需要一些帮助。

<input rel="popover" data-placement="right" data-content="CAPS IS ON" type="password" id="txtPassword" name="password" class="input-xlarge" value="" size="20" />

<script type="text/javascript">
    jQuery('#txtPassword').keypress(function(e) { 
        var s = String.fromCharCode( e.which );
        if ( s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey ) {
            jQuery('#txtPassword').popover('show');
        }
        else {
            jQuery('#txtPassword').popover('hide');
        };
    });
</script>

TRY 尝试

UPDATE 更新

HTML 的HTML

Type Here:<br><input type="text" id="textbox"><br>On each keypress I will tell if caps lock is on<br><br> CAPS LOCK: <span id="cap"></spa n> Type Here:<br><input type="text" id="textbox"><br>On each keypress I will tell if caps lock is on<br><br> CAPS LOCK: <span id="cap"></spa n>

JQUERY JQUERY

//<![CDATA[ 
$(window).load(function(){
$('#textbox').keypress(function(e) { 
    var s = String.fromCharCode( e.which );
    if (s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey) {
        $('#cap').removeClass('red').addClass('green').html('ON');
    } else {
        $('#cap').removeClass('green').addClass('red').html('OFF');
    }
});
});//]]> 


css
.red {
  color: red;    
  font-weight:bold;
}
.green {
  color: green;
  font-weight:bold;    
}

Update Answer: to detect Capital letter 更新答案:检测大写字母

Here is the DEMO http://jsfiddle.net/yeyene/Z52Az/4/ 这是演示http://jsfiddle.net/yeyene/Z52Az/4/

Use this script, 使用此脚本,

$('#txtPassword').keyup(function () {
    var character = $('#txtPassword').val();
    var lastChar = character.substr(character.length - 1);
    if (lastChar == lastChar.toUpperCase()) {
        alert ('You typed capital letter!');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM