最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

onkeydown - JavaScript run function keydown - Stack Overflow

programmeradmin6浏览0评论

I cant find an answer to this that I understand. I want with JavaScript (not 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 :(

I cant find an answer to this that I understand. I want with JavaScript (not 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 :(

Share Improve this question edited Jun 2, 2016 at 12:29 Jeremy Karlsson asked Jun 6, 2011 at 15:53 Jeremy KarlssonJeremy Karlsson 1,0893 gold badges17 silver badges28 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10
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/GuvRP/1/

发布评论

评论列表(0)

  1. 暂无评论