Home > Web Front-end > JS Tutorial > A solution to the problem that the first non-hidden element in a form gets focus_Form special effects

A solution to the problem that the first non-hidden element in a form gets focus_Form special effects

WBOY
Release: 2016-05-16 18:43:13
Original
1146 people have browsed it

There are many elements in form, which are represented by, for example, form.element[x];
The type of an element: The type of an element is represented by element.type
With the above understanding, let us now Let’s solve the first solution for non-hidden elements to gain focus:
First define an object as the method’s applicator:
var f=new Object();
Then:

Copy code The code is as follows:

f.getTheFirstFocus=function(){
if (document.forms.length > ; 0){
for (var i=0; i < document.forms[0].elements.length; i ) //Traverse elements
{ 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