以下是完整的功能性代码.可方便使用. //FormUtil.js var FormUtil = new Object;// 找到第一个表单的第一个元素,并得到焦点FormUtil.focusOnFirst = function ()...{ if (document.forms.length>0)...{ //检测是否有一个表单 for(var i=0;i<document.forms[0].length-1;i++) //表单内元素循环 ...{ var oField = document.forms[0].elements[i]; if(oField.type!="hidden")...{ //如果不是隐藏元素,则得到焦点 //alert(oField.type); oField.focus(); return; } } } }//表单中元素得到焦点同时选择FormUtil.setTextboxes = function()...{ var colInputs = document.getElementsByTagName("input"); var colTextAreas = document.getElementsByTagName("textarea"); for(var i=0;i<colInputs.length;i++)...{ if(colInputs[i].type=="text" || colInputs[i].type=="password")...{ colInputs[i].onfocus = function()...{ this.select();}; } } for(var i=0;i<colTextAreas.length;i++)...{ colTextAreas[i].onfocus = function ()...{ this.select();}; }}//文本框达到最大长度时自动切换到下一个FormUtil.tabForward = function (oTextbox)...{ var oForm = oTextbox.form; //make sure the textbox is not the last field in the form; if(oForm.elements[oForm.elements.length-1] !=oTextbox && oTextbox.value.length==oTextbox.getAttribute("maxlength") )...{ for(var i= 0;i<oForm.elements.length;i++)...{ if(oForm.elements[i]==oTextbox )...{ for(var j=i+1;j<oForm.elements.length;j++)...{ if(oForm.elements[j].type!="hidden")...{ oForm.elements[j].focus(); return } } return; } } }}