0

メニューがあるhtmlページがあります。メニューにはjavascriptがあります。このJavaScriptでは、キーボードのキー1が押された場合、最初のメニューのリンクを呼び出します。これは正常に機能していましたが、現在、要件は17〜18メニューに増えています。つまり、ユーザーが16を押した場合(つまり、キー1、次にキー6)、16番目の番号付きメニューを表示する必要があります。同時に押された2つのキーを特定するのに役立ちます。

if(event.keyCode==49)
            {
                self.location="pages/abc/finishgoods.jsp";

            }
            if(event.keyCode==50)
            {
                window.navigate("pages/submenu.jsp");

            }

誰かがこれを検出するのを手伝ってくれませんか。私のページはIE6用であるため、jqueryを使用できません

4

1 に答える 1

1

これらの線に沿った何か(テストされていませんが、理論はここにあります)

var current_keys = [], // to store keypresses
    key_timer;

// on press, store the current key and give the user a little while to press another
// on keypress {
  current_keys.push(event.keyCode);
  clearTimeout(keyTimer); // refresh the timer
  keyTimer = setTimeout(interpret_keys, 250);
// }

// they've had their chance, work out what they pressed
function interpret_keys ()
{
  var keys = -1
      key,
      i = 0;

  for (i; i < current_keys.length; i++)
  {
    key = current_keys[i] - 48; // turn 48 to 0, 49 to 1, etc
    key >= 0 && key <= 9 && keys += '' + key; // only 0-9 is valid here
  }

  keys = parseInt(keys); // make sure it's a number
  current_keys = []; // reset the tracking variable

  // keys now contains (theoretically) a number such as 1, 2, 16, etc, which can map to your selectable item
}
于 2012-10-25T09:44:11.540 に答える