Home > Web Front-end > JS Tutorial > body text

默认让页面的第一个控件选中的javascript代码_表单特效

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

当页面上面显示了一个表单后,通常焦点 并不是放在第一个控件上面,只需要一点通常的脚本就可以实现这个效果 。
document.forms[0].elements[0].focus();
如果页面的第一个控件是隐藏字段,或是不支持focus() 上面这段javascript 可能就会出现错误 !

复制代码 代码如下:

var formutil = new Object;
formutil.focusOnfirst = function()
{
if(document.forms.length>0){
var item = document.forms[0].elements.length;
for(var i=0;iif(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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!