Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在html中按F2键打开链接或按钮?_Javascript_Html - Fatal编程技术网

Javascript 如何在html中按F2键打开链接或按钮?

Javascript 如何在html中按F2键打开链接或按钮?,javascript,html,Javascript,Html,这是我的密码 <a href="https://www.google.co.in">Google.com</a> 我想在按下F2键或任何功能键时打开它…这里您可以使用jquery实现您的需求:jsfiddle.net/96rLf/2。 document.onkeydown = function(){ if(window.event && window.event.keyCode == 113) { window.location.href =

这是我的密码

<a href="https://www.google.co.in">Google.com</a>


我想在按下F2键或任何功能键时打开它…

这里您可以使用jquery实现您的需求:jsfiddle.net/96rLf/2。

document.onkeydown = function(){
if(window.event && window.event.keyCode == 113) 
{
   window.location.href = "http://www.google.com"
}
}
主要部分是: 您可以使用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
});

$(窗口).keydown(函数(e){
开关(如钥匙代码){
案例37:案例38://钥匙在左边或上面
if(currImage=maxImages){break;}//if是最后一个,什么也不做
goToNext();//转到下一个图像的函数
return false;/“return false”将避免进一步的事件
}
return;//使用“return”将执行其他附加事件
});

您可以使用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,依此类推。


<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>
文件。添加的监听器(“keydown”,keydown,false); 功能键控(e) { var-keyCode=e.keyCode; 如果(keyCode==113){window.location.href=”http://www.google.com";} }
可能重复感谢您指出这一点……我认为重定向的正确语法是:
window.location.href=https://www.google.co.in';
.document.onkeydown=function(){if(window.event&&window.event.keyCode==113){window.location('https://www.google.co.in“”;}}因为它不是working@HashirHussain现在就看答案。我已经更新了。它可以工作了。谢谢。。。。