如何在Html.TextBoxFor(或Html.TextBox)中自动制表符(光标)? [英] How to Auto Tab(Cursor) in Html.TextBoxFor(or Html.TextBox)?
问题描述
我是ASP.NET MVC 4的新手,我有任何疑问
I'm new in ASP.NET MVC 4, and I have any questions
此图片(链接)后面有5个文本框.
I have 5 Textbox following This Picture(Link).
http://i.stack.imgur.com/hMjJp.png
在每个文本框中,我为其设置maxlength.跟随此图片(链接)
in each textbox I set maxlength for its. Following This Picture(Link)
http://i.stack.imgur.com/rSi4U.png
Example : textbox1 -> maxlength = 1
textbox2 -> maxlength = 4
textbox3 -> maxlength = 5
当我在每个文本框中插入数据时,我想自动制表.
I want to auto tab when i insert data to each textbox.
Example : when I insert "1" to textbox1(maxlength=1) cursor will go to textbox2 AUTO
然后我想将数据设置为所有"文本框
And thereafter I want to set data as All textbox
示例:字符串值= textbox1 + textbox2 + ... + textbox5
Example : string value = textbox1 + textbox2 + ... + textbox5
value = 1222233333...
对于可能发生的任何错误,请提前接受我的真诚道歉.
Please accept my sincere apology in advance for any mistake that may occur.
非常感谢您.
推荐答案
类似下面的方法应该起作用,
Something like following should work,
标记
<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/
希望这会有所帮助.
这篇关于如何在Html.TextBoxFor(或Html.TextBox)中自动制表符(光标)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!