2014-02-18 124 views

回答

0

你可以使用的onkeydown方法。

document.onkeydown = function(){ 
if(window.event && window.event.keyCode == 113) 
{ 
    window.location.href = "http://www.yoursite.com" 
} 
} 

在這裏,你可以用任何東西來代替113.F2是113 ascii.F1是112,F3是114等等。

+0

它的工作原理感謝.. .. –

+0

歡迎您... –

1
document.onkeydown = function(){ 
if(window.event && window.event.keyCode == 113) 
{ 
    window.location.href = "http://www.google.com" 
} 
} 
+0

感謝指出了這一點... –

+0

的可能重複。我想,該重定向的正確語法是:'window.location.href ='https://www.google.co.in';'。 – 2014-02-18 05:13:59

+0

是否正確 '<!DOCTYPE HTML> Google.com ',因爲它不工作 –

0

在這裏,你有使用jQuery您的要求的實現:的jsfiddle。淨/ 96rLf/2。

主要部分是這樣的:jsfiddle.net/96rLf/2. 您可以使用jQuery

<input type="button" accesskey="?" value="Next Item"> 

$(window).keydown(function(e) { 
    switch (e.keyCode) { 
     case 37: case 38: //key is left or up 
      if (currImage <= 1) {break;} //if is the first one do nothing 
      goToPrev(); // function which goes to previous image 
      return false; //"return false" will avoid further events 
     case 39: case 40: //key is left or down 
      if (currImage >= maxImages) {break;} //if is the last one do nothing 
      goToNext(); // function which goes to next image 
      return false; //"return false" will avoid further events 
    } 
    return; //using "return" other attached events will execute 
}); 
0
<html> 
<head> 
    <script> 
     document.addEventListener("keydown", keyDown, false); 

     function keyDown(e) 
     { 
      var keyCode = e.keyCode; 
      if(keyCode==113) {window.location.href = "http://www.google.com";} 
     } 
    </script> 
</head> 
<body> 
    <a href="https://www.google.co.in">Google.com</a> 
</body> 
</html> 
+0

其工作感謝.... –

相關問題