Home > Web Front-end > JS Tutorial > JavaScript聚焦于第一个字段的代码_表单特效

JavaScript聚焦于第一个字段的代码_表单特效

WBOY
Release: 2016-05-16 18:18:26
Original
825 people have browsed it

这个主要会用在表单字段中,所以我这里做的实验只针对表单字段。在form的子元素中循环查找第一个不是隐藏字段的字段,然后使用focus方法获得焦点。(呵呵^_^,很简单!)

复制代码 代码如下:

FormUtil.focusOnFirst = function() {
if (document.forms.length > 0) {
for (var i = 0; i var oField = document.forms[0].elements[i];
if (oField.type != "hidden") {
oField.focus();
return;
}
}
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template