Home > Web Front-end > JS Tutorial > The javascript code that makes the first control on the page selected by default_form effects

The javascript code that makes the first control on the page selected by default_form effects

WBOY
Release: 2016-05-16 18:38:06
Original
1083 people have browsed it

When a form is displayed on the page, the focus is usually not on the first control. This effect can be achieved with just a little common script.
document.forms[0].elements[0].focus();
If the first control on the page is a hidden field, or does not support focus(), the above javascript may cause an error!

Copy code The code is as follows:

var formutil = new Object;
formutil.focusOnfirst = function()
{
if(document.forms.length>0){
var item = document.forms[0].elements.length;
for(var i=0;i< ;item;i ){
if(document.forms[0].elements[i].type !="hidden"){
document.forms[0].elements[i].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