开发者

Show the Key(letter) pressed in a div using javascript not jquery

开发者 https://www.devze.com 2023-02-28 04:48 出处:网络
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

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.)

0

精彩评论

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