문자수를 지정하여 다음칸으로 이동시키기 (autoTab)

2019. 12. 5. 15:24PROGRAMMING/JavaScript & JQuery

간단한 소스라 설명은 생략하겠습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html>
    <head>
        <title>입력창 자동으로 탭 넘기기</title>
    
        <script type="text/javascript">
            function AutoTab(me, next, iLen)
            {
                
                if ($(me).val().length == iLen) {
                    $("#"+next).focus();
                }
            }
        </script>
    </head>
    <body>
        <form name="autoTab" id="autoTab" method="post" >
            <input type="text" id="text1" maxlength="5" onkeyup = "AutoTab(this, 'text2', this.maxLength)" />
            <input type="text" id="text2" maxlength="4" onkeyup = "AutoTab(this, 'text3', this.maxLength)" />
            <input type="text" id="text3" maxlength="3" onkeyup = "AutoTab(this, 'text4', this.maxLength)" />
            <input type="text" id="text4" maxlength="2" />
        </form>
    </body>
</html>

 

테스트 해보세요!!