按键增量数(JavaScript)[关闭]

I am trying to display a paragraph tag on the screen using html. I want to then be able to press a key and have the number in that paragraph tag increase. That is all that I want to do.

This seems like it should be easy to do but I don't know how to do it.

Thanks.

Check this out. This is without jQuery, but it's what you are looking for.

http://jsfiddle.net/2rAj9/

The JS:

var p = document.querySelector('p')

document.addEventListener('keydown', increment, false);

function increment() {
    var number = parseInt(p.innerText);
    number++;
    p.innerText = number;
}

The HTML:

<p class="increment">0</p>

Using jQuery:

Jquery:

$(document).ready(function(){
    $('body').keydown(function(){
        console.log('keydown');
        $('#increment').text(parseInt($('#increment').text())+1);   
    });

});

HTML:

<p id="increment">0</p>