我有一个类型为的简单输入,time我尝试在 DOM 树中设置自动聚焦下一个输入
<input type="time" name="startTime" (keyup)="setFocus($event)"/>
setFocus(element) {
if (element.target.value.length == 5) {
let coll = document.getElementsByTagName('input');
let array = Array.from(coll)
let thisOne = array.forEach((el) => {
if (el == element.target) {
let index = array.indexOf(el)
let next = array[index + 1]
next.focus();
next.select();
}
});
}
}
问题是当时间具有默认值时,值长度始终为 5(在 keyup 上),如05:45or 18:22,那么我该如何设置下一个自动对焦?有没有办法找出光标在第 5 位?任何想法?