开发者

JavaScript run function keydown

开发者 https://www.devze.com 2023-03-11 14:42 出处:网络
I cant find an answer to this that I understand. I want with JavaScript (n开发者_运维知识库ot jQuery) to make it so if thewith the id boxFilm is visible and I click on \"SPACE\" (keycode 32), the func

I cant find an answer to this that I understand. I want with JavaScript (n开发者_运维知识库ot jQuery) to make it so if the with the id boxFilm is visible and I click on "SPACE" (keycode 32), the function togglep(); runs.

How do I do this? I've tried many things but haven't succeeded :(


function togglep(){
    alert("Hi");
}

document.body.onkeydown = function(event){
    event = event || window.event;
    var keycode = event.charCode || event.keyCode;
    if(keycode === 32){
        togglep();
    }
}

try it here: http://jsfiddle.net/GuvRP/1/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号