0

When i open login page if the caps lock is on i need to show immediately caps lock is on. I saw some posts like

this Which is showing in keypress.But i want to show immediately after page loaded. How i can do this using jQuery .Please help me.Thanks in advance.

4

2 に答える 2

1

特定のフィールドだけでなく、ページ全体のキャップス ロック キーの状態を監視する capslockstate と呼ばれる jQuery プラグインがあります。

Caps Lock キーの状態を照会するか、状態の変化に反応するイベント リスナーを定義できます。

このプラグインは、英語以外のキーボードでの作業、Caps Lock キー自体の使用の監視、アルファベット以外の文字が入力された場合に状態を忘れないなど、ここでの他の提案よりも検出と状態管理の優れた仕事をします.

2 つのデモがあり、1 つは基本的なイベント バインディングを示し、もう1 つはパスワード フィールドにフォーカスがある場合にのみ警告を示します

例えば

$(document).ready(function() {

/* 
* Bind to capslockstate events and update display based on state 
*/
$(window).bind("capsOn", function(event) {
    $("#statetext").html("on");
});
$(window).bind("capsOff", function(event) {
    $("#statetext").html("off");
});
$(window).bind("capsUnknown", function(event) {
    $("#statetext").html("unknown");
});

/*
* Additional event notifying there has been a change, but not the state
*/
$(window).bind("capsChanged", function(event) {
    $("#changetext").html("changed").show().fadeOut();
});

/* 
* Initialize the capslockstate plugin.
* Monitoring is happening at the window level.
*/
$(window).capslockstate();

// Call the "state" method to retreive the state at page load
var initialState = $(window).capslockstate("state");
$("#statetext").html(initialState);});

$(document).ready(function() {

/* 
* Bind to capslockstate events and update display based on state 
*/
$(window).bind("capsOn", function(event) {
    if ($("#Passwd:focus").length > 0) {
        $("#capsWarning").show();
    }
});
$(window).bind("capsOff capsUnknown", function(event) {
    $("#capsWarning").hide();
});
$("#Passwd").bind("focusout", function(event) {
    $("#capsWarning").hide();
});
$("#Passwd").bind("focusin", function(event) {
    if ($(window).capslockstate("state") === true) {
        $("#capsWarning").show();
    }
});

/* 
* Initialize the capslockstate plugin.
* Monitoring is happening at the window level.
*/
$(window).capslockstate();});

プラグインのコードはGitHub で表示できます。

于 2013-04-15T04:56:33.293 に答える
0

申し訳ありませんが、ページの読み込み時にキーボード ボタンの状態を取得することはできません。キープレスのキーコードを分析する必要があります。それが唯一の方法です。

この投稿を確認してください:ページの読み込み時に Caps Lock ステータスを検出する (または同様の)

于 2013-04-15T04:40:21.637 に答える