करते हुए देखें मैं एक पाठ बॉक्स के लिए 1 के रूप में maxlength स्थापित करने का सुझाव देते हैं और अगले एक एक बार val.length
करने के लिए स्विच जाएगा और maxlength
में ही है।
DEMO
$(".inputs").keyup(function() {
if (this.value.length == this.maxLength) {
$(this).next('.inputs').focus();
}
});
संपादित करें: निम्नलिखित के लिए कुछ समय बिताया (पूरी तरह से परीक्षण नहीं है, लेकिन बुनियादी परीक्षण ठीक काम किया)
1. Allowing just numeric chars
2. Allow some control like del, backspace, e.t.c
3. Backspace on empty textbox will move to prev textbox
4. charLimit var to dynamically decide how many char you want to restrict.
कोड:
$(function() {
var charLimit = 1;
$(".inputs").keydown(function(e) {
var keys = [8, 9, /*16, 17, 18,*/ 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];
if (e.which == 8 && this.value.length == 0) {
$(this).prev('.inputs').focus();
} else if ($.inArray(e.which, keys) >= 0) {
return true;
} else if (this.value.length >= charLimit) {
$(this).next('.inputs').focus();
return false;
} else if (e.shiftKey || e.which <= 48 || e.which >= 58) {
return false;
}
}).keyup (function() {
if (this.value.length >= charLimit) {
$(this).next('.inputs').focus();
return false;
}
});
});
DEMO
स्रोत
2012-05-10 17:27:29
यह पोस्ट देखें [1] के लिए अनुकूल करने में संकोच न: http://stackoverflow.com/questions/1232379/सेटिंग-द-फोकस-टू-द-अगली-इनपुट-इन-jquery – BinBin
कुछ नई सुविधाओं के लिए [अपडेटेड पोस्ट] (http://stackoverflow.com/a/10539258/297641) देखें .. अधिक ' autotab' [डेमो] (http://jsfiddle.net/skram/qygB2/4/) –