Сценарий: мне нужно изменить фокус ввода, когда пользователь нажимает клавишу ввода. тип ввода - дата. например, когда фокус находится на «дне» и пользователь нажимает клавишу ввода, фокус должен измениться на месяц (точно так же, как при нажатии табуляции).
возможно, этот фрагмент поможет решить проблему:
first I have tried to get the next element by querySelectorAll but the next element is the next input not next digit in the input.
function focusNextElement() {
//add all elements we want to include in our selection
var focussableElements =
'a:not([disabled]), button:not([disabled]), input:not([disabled]), [tabindex]:not([disabled]):not([tabindex="-1"])';
if (document.activeElement && document.activeElement.form) {
var focussable = Array.prototype.filter.call(
document.activeElement.form.querySelectorAll(focussableElements),
function(element) {
//check for visibility while always include the current activeElement
return (
element.offsetWidth > 0 ||
element.offsetHeight > 0 ||
element === document.activeElement
);
}
);
var index = focussable.indexOf(document.activeElement);
if (index > -1) {
var nextElement = focussable[index + 1] || focussable[0];
nextElement.focus();
}
}
}
есть идеи?