0

我有一个 html 页面,上面有菜单。菜单有一个javascript。在这个 javascript 中,如果按下键盘键 1,那么我调用第一个菜单的链接,这工作正常,但现在要求增加到 17-18 个菜单。也就是说,如果用户按下 16(即按键 1,然后按键 6),则必须显示第 16 个编号的菜单。我需要帮助确定同时按下了哪两个键。

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

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

            }

任何人都可以帮助我检测到这一点。我不能使用 jquery,因为我的页面适用于 IE 6

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