0

我正在使用 QWERTZ 键盘并想为文本输入字段编写验证脚本。不幸的是,无论我尝试什么,Chrome 中仍然会显示以下字符:^ 和 ´,即使我只允许某些键并e.preventDefault()用于其他键。

我还尝试不允许使用此语句进行大写锁定

if(e.originalEvent.getModifierState("CapsLock")==true)

但在具有活动 capsLock 的 Chrome 控制台中,它总是返回 false。

在 Firefox 中一切正常。这是什么原因,我该如何解决?

4

1 回答 1

0

在 jQuery 中:

$('#yourInputText').keypress(function(e) { // or catch any other event you want
    var s = String.fromCharCode( e.which );
    if ( s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey ) {
        alert('caps is on');
    }
});
于 2015-03-02T12:37:29.480 回答