0

ユーザーがを入力しクリックしたときにシフトが押された場合は、新しいウィンドウを開こうとイム、と彼らはCTRLをヒットした場合、新しいタブ。 シフト一部の作品が、CTRL一部にはない...私のコードがCtrlキーの状態を検出できないのはなぜですか?

var ctrlPressed = false; 
var shiftPressed = false; 
var stb = null; 
function onload() { 
stb = document.getElementById("searchTextBox"); 
} 
    function enter(e) { 

     if (e.keyCode == 13) { 
      if (!ctrlPressed && !shiftPressed) { 
      window.location = "http://search.yahoo.com/search?p=" + encodeURI(stb.value) + "&fr2=sb-top&fr=404_web&pqstr=" + encodeURI(stb.value); 
      } 
      else if (ctrlPressed) { 
      window.open("http://search.yahoo.com/search?p=" + encodeURI(stb.value) + "&fr2=sb-top&fr=404_web&pqstr=" + encodeURI(stb.value)); 
      } 
      else if (shiftPressed) { 
      window.open("http://search.yahoo.com/search?p=" + encodeURI(stb.value) + "&fr2=sb-top&fr=404_web&pqstr=" + encodeURI(stb.value), "_blank"); 
      } 
     } 
    } 
    function searchdown(e) { 
     if (e.keyCode == 17) { 
      ctrlPressed = true; 
     } 
     else if (e.keyCode == 16) { 
      shiftPressed = true; 
     } 
    } 
    function searchup(e) { 
     if (e.keyCode == 17) { 
      ctrlPressed = false; 
     } 
     else if (e.keyCode == 16) { 
      shiftPressed = false; 
     } 
    } 

は、[編集]また、私はjqueryの

+0

イベントの委任はどこですか? –

答えて

2

を使用するカントコントロールキーがある場合、約event.ctrlKeyわかりますどのを知っていました押された?

+0

ええ、私は最初にそれを持っていたので、私はこの方法を試した – Oztaco

関連する問題