I want to get the user's input key value, 开发者_运维技巧if user click "confirm" key , I will direct the page to some othe page, now i don't know how to confir user click the "confirm" key.
It might help if you mentioned what platform you are developing for.
Perhaps something like this would work:
document.addEventListener('keypress', function(e){
alert(e.keyCode);
}, false);
This code should tell you the keyCode for the button. Then you can replace the alert with an if statement (let's say the confirm button produces a keyCode of 111):
if(e.keyCode === 111){
//redirect to other page
}
Your use of javascript should be limited to high end smart phones (i.e. iPhone/Android). On other devices, you will find any one of the following scenarios:
- There is no javascript support
- The javascript is only partially implemented
- Even it is implemented well enough for you to use the code Ronald posted, javascript may be disabled by default. And chances are slim that an ordinary user will know how to turn it on.
You can use tools like WURFL or DeviceAtlas to help determine the capabilities of the mobile device - but a good rule of thumb is avoid javascript unless you're sure the device can handle it.
Rgds, Kevin.
精彩评论