Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DevCodo/7aedf91ce09b5800c9448068c0b23ae8 to your computer and use it in GitHub Desktop.

Select an option

Save DevCodo/7aedf91ce09b5800c9448068c0b23ae8 to your computer and use it in GitHub Desktop.
function setSelectionRange(input, selectionStart, selectionEnd) { // функция для постановки курсора
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
range.select();
}
}
$(".tel").each(function() { // маска для ввода телефона через плагин jquery.maskedinput
$(this).mask("+7(999) 999-9999");
$(this).on("click", function() {
setSelectionRange(this, 3, 3)
})
$(this).on("keyup", function() {
if ( $(this).val() == "+7(8__) ___-____" ) {
var e = $.Event("keydown", { keyCode: 8});
$(this).trigger(e);
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment