Код: Выделить всё
Please type Enter to move to the next element
Confirm
Код: Выделить всё
const selects = document.querySelectorAll('.item');
selects.forEach(el => el.addEventListener('keyup', e => {
if (e.key === 'Enter' || e.keyCode === 13) {
let idx = parseInt(e.currentTarget.getAttribute("index"));
focusToTheNextControl(idx);
}
}));
document.querySelector('.btn-item').addEventListener('click', e => {
let idx = parseInt(e.currentTarget.getAttribute("index"));
focusToTheNextControl(idx);
});
function focusToTheNextControl(idx) {
document.querySelector("#item-" + (idx + 1)).focus();
}
Код: Выделить всё
const selects = document.querySelectorAll('.item');
selects.forEach(el => el.addEventListener('keyup', e => {
if (e.key === 'Enter' || e.keyCode === 13) {
let idx = parseInt(e.currentTarget.getAttribute("index"));
focusToTheNextControl(idx);
}
}));
document.querySelector('.btn-item').addEventListener('click', e => {
let idx = parseInt(e.currentTarget.getAttribute("index"));
focusToTheNextControl(idx);
});
function focusToTheNextControl(idx) {
document.querySelector("#item-" + (idx + 1)).focus();
}Код: Выделить всё
Please type Enter to move to the next element
Confirm
Я пытаюсь отложить фокус на следующем элементе, используя setTimeout через 1 секунду и оно останавливается. Я понятия не имею, как это работает и как правильно это остановить.
Спасибо за помощь.
Подробнее здесь: https://stackoverflow.com/questions/792 ... button-and
Мобильная версия