window.onload=initForm;function initForm(){ for(var i=0;i<document.forms.length;i++){ document.forms[i].onsubmit=function(){return validForm();} } } function validForm(){ var allGood=true; var allTags=document.getElementsByTagName("*"); for(var j=0;j<document.allTags.length;j++){ if(!validTag(allTags[j])){ allGood=false; } } return allGood; function validTag(thisTag){ var outclass=" "; var allClass=thisTag.className.split(" "); for(var k=0;k<allClass.length;k++){ outclass+=basic(allClass[k])+" "; } } thisTag.className=outclass; if(outclass.indexOf("invalid")>-1){ this.focus(); if(thisTag.nodeName=="INPUT"){ this.select(); } return false; } return true; function basic(thisClass){ var classback=" "; switch(thisClass){ case " ": case "invalid": break; case "password1": if(allGood&&thisTag.value==""){ classback="invalid "; } classback+=thisClass; break; default: classback+=thisClass; } return classback; } }
添加回答
举报
0/150
提交
取消