有人可以解释遵循代码的含义吗
function handleEnter(event) {
if (event.key==="Enter") {
const form = document.getElementById('form')
const index = [...form].indexOf(event.target);
form.elements[index + 1].focus();
}
}
按下Enter Enter Some Some Some Offer Inluce逐行解释我,该代码用于关注下一个输入字段?这将是很大的帮助
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第1行:
从HTML行2获取DOM元素
:
以“当前元素”索引以元素查找。我认为这行不正确,我想您想从表单元素中获取子元素,如果是这样,则应该是:
第3行:
下一个元素应该是当前索引加1,所以只需运行
focus
在下一个元素上,但是正如我说的,我认为您的第2行
是不正确的,因此该行应该是:Line 1:
Get the DOM element from html
Line 2:
Find in the form elements the index of the current element. I think this line is not correct, I suppose that you want to get child elements from the form element, if so, it should be something like:
Line 3:
The next element should be the current index plus 1, so just run
focus
on next element, but as I said, I think that yourline 2
is not correct so this line should be something like:据我了解。
第二行:仅在按Enter键时,此功能才能执行
第三行:从表单输入(“形式” ID)获取信息
第四行:获取表单输入的索引
第五行:将焦点移动到下一个元素(index+1)
As I understand.
2nd line : This funct will perform only when press Enter key
3rd line : get information from the form input ("form" ID)
4th line : get the index of the form input
5th line : move the focus point to the next element (which is index+1)
兄弟,了解此代码非常容易,您只需要分解它即可。
让我们从它开始: -
Bro, understanding this code is quite easy you just need to break it down.
Let's start with it :-