=>HTML文比抖朋要插支一圈不者地件
表单验证_密码验证YourName:
ChooseAPassword:
VerifyPassword:
=>样式文件
body {
color: #000; //黑色;
background-color: #FFF; //白色;
}
input.invalid {
background-color: #FF9; //黄色;
border: 2px red inset;
}
label.invalid {
color: #F00; //红色;
font-weight: bold;
}
=>脚遇新是直朋能到分览本文件
window.onload = initForms;
function initForms() {
for(var i=0, len=document.forms.length; i
document.forms[i].onsubmit = function() {
return validForm();
}
}
}
function validForm() {
var allGood = true; // 默认验证通过;
var allTags = document.getElementsByTagName("*");
for(var i=0; i
if(!validTag(allTags[i])) {
allGood = false;
}
}
return allGood;
/*validForm(结束;*/
function validTag(thisTag) {
var outClass = "";
var allClasses = thisTag.className.split(" ");
for(var j=0,len=allClasses.length; j
outClass += validBasedOnClass(allClasses[j]) + " ";
}
thisTag.className = outClass;
// console.log(i);
// console.log(thisTag.id);
// console.log(outClass);
if(outClass.indexOf("invalid") > -1) {
thisTag.className = outClass.substring(0,7);
console.log(thisTag.className);
thisTag.focus();
if(thisTag.nodeName == "INPUT") {
thisTag.select();
}
return false;
}
return true;
/*validTag()函数结束;*/
function validBasedOnClass(thisClass) { // 只有空、reqd、passwd1;
var classBack = "";
switch(thisClass) {
case "":
case "invalid":
break;
case "reqd":
if(allGood && thisTag.value == "") {
classBack = "invalid";
}
classBack += thisClass;
break;
default:
classBack += thisClass;
}
return classBack;
}
}
}
本文来源于网络:查看 >https://blog.csdn.net/cenyebao/article/details/6930463