Javascript 盖帽锁府绸

Javascript 盖帽锁府绸,javascript,jquery,Javascript,Jquery,我试图显示一个弹出窗口,当大写锁定键在输入密码时打开,代码工作正常,弹出窗口在大写打开时显示,不打开时隐藏。但当我点击密码字段时,我也会得到弹出框,即使caps没有打开 我需要一些帮助 <input rel="popover" data-placement="right" data-content="CAPS IS ON" type="password" id="txtPassword" name="password" class="input-xlarge" value="" size=

我试图显示一个弹出窗口,当大写锁定键在输入密码时打开,代码工作正常,弹出窗口在大写打开时显示,不打开时隐藏。但当我点击密码字段时,我也会得到弹出框,即使caps没有打开

我需要一些帮助

<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>

jQuery('#txtPassword').keypress(函数(e){
var s=String.fromCharCode(e.which);
if(s.toUpperCase()==s&&s.toLowerCase()!==s&&!e.shiftKey){
jQuery('#txtPassword').popover('show');
}
否则{
jQuery('#txtPassword').popover('hide');
};
});
试试看

更新

HTML

在此处键入:

在每次按键时,我都会告诉您caps lock是否处于启用状态

caps lock:

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;    
}
//
css
瑞德先生{
颜色:红色;
字体大小:粗体;
}
格林先生{
颜色:绿色;
字体大小:粗体;
}
更新答案:检测大写字母 这是演示

使用这个脚本

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

鼠标单击时不应触发
按键
事件。请显示您的全部代码,可能带有指向的链接。这很好,我的代码也一样。我的问题是,我在单击时收到了一个不必要的popover。请再次检查我的更新答案。是否要检测caps lock on,对吗?是否在caps lock开启时按shift+小字符。capslock关闭时否…我按“shift+small character”它应该返回capslock处于启用状态。您希望只检测大写字母,而不是CAPS lock处于启用状态。