开发者

Is it possible to share a virtual keyboard with multiple textboxes?

开发者 https://www.devze.com 2023-01-25 15:56 出处:网络
I\'ve got a screen keyboard that I want to share with 3 textboxes. If the user clicks input button \"A\", the focus as well as all of the keypresses should go into the \"A\" textbox. If the user press

I've got a screen keyboard that I want to share with 3 textboxes. If the user clicks input button "A", the focus as well as all of the keypresses should go into the "A" textbox. If the user presses the "B" input button, then the focus and the keys pressed should go into the "B" textbox.开发者_如何学JAVA Is this possible? I can't seem to understand how this should work. I'm a total noob to javascript so please, examples would be greatly appreciated. Thanks


You just have to listen to the keypress on the body element. Determine which key it is, then update the focus and the value of the appropriate textbox. Events in javascript bubble up. So if you listen for say keyup on the body, any key press on any element will bubble up to there (unless something along the way cancels it).

Edit: Some code:

...
<script type="text/javascript">
function process(event)
{
   if (event.keyCode == 65) // "a"
   {
       document.getElementById("a").focus();
   }
}
</script>
<body onkeyup="process(event)">
...
</body>
...
0

精彩评论

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