I need to write a javascript code for a 5 letter word game that will detect when a Key(letter) is pressed to show in a div. Each letter of the word should display in its own div. If the player enters a letter and it's one of the letters in the word it should show up in one of the 5 divs if not then it should show in a another set of divs (7), player gets 7 guesses. I just need this part to get me started o开发者_JAVA技巧n the rest of the project.
thanks in advance, greatfulOne
QuirksMode has an awesome page on detecting keystrokes..
To summarize, you'll want to either target the keydown
or keyup
event, and check for the keyCode
property of the event object that is generated.
Some of the more complicated keys have cross-browser difficulties, but you should be okay if you're sticking with a-z. (Could be wrong, but it looks like "a" has a keyCode
of 65, "z" has 90, and the other letters fill in.)
精彩评论