1

私は ASP.NET MVC 4 の初心者で、質問があります

This Picture(Link)の後に5つのテキストボックスがあります。

http://i.stack.imgur.com/hMjJp.png

各テキストボックスで、その最大長を設定しました。この画像をたどる(リンク)

http://i.stack.imgur.com/rSi4U.png

Example : textbox1 -> maxlength = 1
          textbox2 -> maxlength = 4
          textbox3 -> maxlength = 5

各テキストボックスにデータを挿入するときにタブを自動化したい。

Example : when I insert "1" to textbox1(maxlength=1) cursor will go to textbox2 AUTO

その後、データをすべてのテキストボックスとして設定したい

例 : 文字列値 = textbox1 + textbox2 + ... + textbox5

        value = 1222233333...  

間違いが発生する可能性があることをあらかじめお詫び申し上げます。

どうもありがとうございます。

4

1 に答える 1

0

次のようなものが機能するはずです。

マークアップ

<div class="tax">
    <input type="text" maxlength="1" />
    <input type="text" maxlength="4" />
    <input type="text" maxlength="5" />
    <input type="text" maxlength="2" />
    <input type="text" maxlength="1" />
</div>

脚本

$(function () {
    $('.tax input[type="text"]').keypress(function (e) {
        if (e.which == 0 || e.charCode == 0) {
            return true;
        }
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        str = $(this).val() + str;

        if (str.length == $(this).prop('maxlength')) {
            var that = this;
            window.setTimeout(function(){
                $(that).next('input[type="text"]').focus();
            }, 0);
        }
    });
});

フィドル: http://jsfiddle.net/tkasD/5/

お役に立てれば。

于 2013-07-18T06:21:14.963 に答える