Created
July 28, 2018 10:25
-
-
Save almirus/8b190c7a4e5079f46f1c9e5afa3a4964 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div.onkeyup = function(e) { | |
var target = e.srcElement; | |
var keyCode = ('which' in event) ? e.which : e.keyCode; | |
var maxLength = parseInt(target.attributes["maxlength"].value, 10); | |
var position = target.selectionStart; | |
var myLength = target.value.length; | |
// если достигли при вводе макс длины и это не кнопки влево\вправо и курсор в конце строки и нажали вправо | |
if ((myLength >= maxLength && keyCode!==37 && keyCode!==39) || (position===myLength && keyCode===39)) { | |
var next = target; | |
// берем след элемент | |
while (next = next.nextElementSibling) { | |
if (next == null) | |
break; | |
// если это инпут | |
if (next.tagName.toLowerCase() === "input" && next.type!=="hidden") { | |
next.focus(); // ставим курсор | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment