2012-10-25 80 views
0

我有一個有菜單的html頁面。菜單有一個JavaScript。 在這個JavaScript如果鍵盤按鍵1被按下,然後我打電話給第一個菜單的鏈接,這是工作正常,但現在需求增加到17-18菜單。也就是說,如果用戶按16(即鍵1,然後鍵6),則必須顯示第16個編號的菜單。我需要幫助確定哪兩個鍵同時按下。JavaScript來檢測哪個鍵盤按鍵被點擊

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

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

      } 

任何人都可以幫助我檢測到這一點。因爲我的網頁是沿着這些線路IE 6

+8

jQuery的支持IE6 – Aesthete

+0

@唯美主義者。謝謝。我認爲它有有限的支持,我嘗試了日曆(日期選擇器),但我正面臨性能問題,因爲我正在爲手持設備製作它。 –

+0

正如你提到的datepicker,我想你是在談論jQuery UI,這與jQuery –

回答

1

東西我不能使用jQuery的(未經測試,但理論是這裏)

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 
} 
+0

嘿,謝謝喬。代碼工作正常。+ 1從我這裏開始工作,因爲早上你很快爲我破解了它。謝謝。 –