开发者

copy - paste in javascript

I have this code

<input name="mpan[]" value="" maxlength="2" size="2">
<input name="mpan[]" value="" maxlength="2" size="3"> 
<input name="mpan[]" value="" maxlength="2" size="3">
<input name="mpan[]" value="" maxlength="2" size="12">

What I have to do is I am provided with a large key for example 0380112129021. When I do Ctrl+C on that key and select any box and press Ctrl+V, the number automatically get pasted in different box, for example: first input box gets 03, next gets 801, next gets 112 and rest gets pasted on last one 开发者_如何学Python129021.how do i achive this from javascript


If you're looking to catch paste events (rather than the literal Ctrl+V), the onpaste event may be for you, and is supported by most browsers according to this answer.

The splitting of the input value you could do using substring().


Easy. On each of the input box, add an onkeyup handler and inspect the input values.

Little clarification, you're trying to do something like serial/key input boxes, right?


okay if you have no idea you should read through some stuff.

i can recommend to read about

  • javascript - events.
  • especialy the onkeyup/onkeydown events
  • stringparsing (substring)

after that you will see the answer glowing on your screen ;-)

a little hint: if you store the pressed keys to a variable, it should be cleared after the action is triggered. and you should check what you have in you keypress cache and clear illigal input.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜