怎么样能够在HTML页面中输入验证?
Function.registerNamespace("net.bingosoft.web");
net.bingosoft.web.Validators=function(containers){
var_containers=containers?containers:document.body;
var_self=this;
var_errmsg="";
if(!(_containersinstanceofArray)){
_containers=[_containers];
}
this.attach=function(){
if(arguments.length>0){
_self._attach(arguments[0]);
}else{
_self._attach(_containers);
}
}
this._attach=function(obj){
if(!obj)return;
if(!(objinstanceofArray))obj=[obj];
for(vari=0;i<obj.length;i++){
varcontainer=obj[i];
if(container.validator){
container.style.backgroundColor="#DDEEFF";
_self._attachEvents(container);
}
if(container.childNodes)
for(varj=0;j<container.childNodes.length;j++){
varchild=container.childNodes[j];
_self._attach(child);
}
}
}
this._attachEvents=function(obj){
varvalidatorNames=(obj.validator.trim()).split(/s*,s*/g);
varlen=validatorNames.length;
for(vari=len-1;i>=0;i--){
varvalidatorName=validatorNames[i].toLowerCase();
varvaliatorTypeName=_self._upperFirstLetter(validatorName)+"Validator";
varnamespace=typeof(obj.vnamespace)=='undefined'?"net.bingosoft.web":obj.vnamespace;
if(namespace)valiatorTypeName=namespace+"."+valiatorTypeName;
varfn=Function.parse(valiatorTypeName);
if(!fn){
alert('cannotfindvalidator:'+valiatorTypeName);
}else{
varvalidator=newfn(obj,validatorName);
varevents=validator.getEvents();
if(events){
vararrEvents=events.split(/s*,s*/g);
for(varj=0;j<arrEvents.length;j++){
obj.attachEvent(arrEvents[j],validator._doValidate);
}
}
}
}
}
this._getNamespace=function(obj,validatorName){
varns=validatorName+"_namespace";
if(obj[ns])returnobj[ns];
if(obj.vnamespace)returnobj.vnamespace;
return"net.bingosoft.web";
}
this._check=function(obj){
varvalidatorNames=(obj.validator.trim()).split(/s*,s*/g);
varlen=validatorNames.length;
for(vari=len-1;i>=0;i--){
varvalidatorName=validatorNames[i].toLowerCase();
varvaliatorTypeName=_self._upperFirstLetter(validatorName)+"Validator";
varnamespace=_self._getNamespace(obj,validatorName);
if(namespace)valiatorTypeName=namespace+"."+valiatorTypeName;
varfn=Function.parse(valiatorTypeName);
if(!fn){
alert('cannotfindvalidator:'+valiatorTypeName);
}else{
varvalidator=newfn(obj,validatorName);
if(!validator._doValidate())returnfalse;
}
}
returntrue;
}
this._upperFirstLetter=function(inputString){
if(!inputString)returninputString;
varfirst=inputString.substring(0,1).toUpperCase();
varleft=inputString.substring(1);
returnfirst+left;
}
this.validate=function(){
if(arguments.length>0){
_self._validate(arguments[0]);
}else{
return_self._validate(_containers);
}
}
this._validate=function(obj){
if(!obj)returntrue;
if(!(objinstanceofArray))obj=[obj];
for(vari=0;i<obj.length;i++){
varcontainer=obj[i];
if(container.validator){
if(!_self._check(container))returnfalse;
}
if(container.childNodes)
for(varj=0;j<container.childNodes.length;j++){
varchild=container.childNodes[j];
if(!_self._validate(child))returnfalse;
}
}
returntrue;
}
}
net.bingosoft.web.Validators.registerSealedClass("net.bingosoft.web.Validators",null,null);
net.bingosoft.web.Validators._attachBodyReadyState=function(){
if(document.readyState=="complete"){
window.$validator=newnet.bingosoft.web.Validators();
window.$validator.attach();
}
}
document.attachEvent("onreadystatechange",net.bingosoft.web.Validators._attachBodyReadyState);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//{validator}_message
//{validator}_namespace
//{validator}_events
//vmessage
//vnamespace
//venvents
//vrealtime
net.bingosoft.web.Validator=function(element,validatorName){
net.bingosoft.web.Validator.initializeBase(this);
var_element=element;
if(!_element)thrownewError("cannotfoundhtmlelement!");
if(!validatorName)thrownewError("cannotfoundparam'validatorName'");
if(typeof(_element.validate_next)=='undefined'){
_element.validate_next=true;
//_element.style.backgroundColor="blue";
}
var_validatorName=validatorName;
net.bingosoft.web.Validators=function(containers){
var_containers=containers?containers:document.body;
var_self=this;
var_errmsg="";
if(!(_containersinstanceofArray)){
_containers=[_containers];
}
this.attach=function(){
if(arguments.length>0){
_self._attach(arguments[0]);
}else{
_self._attach(_containers);
}
}
this._attach=function(obj){
if(!obj)return;
if(!(objinstanceofArray))obj=[obj];
for(vari=0;i<obj.length;i++){
varcontainer=obj[i];
if(container.validator){
container.style.backgroundColor="#DDEEFF";
_self._attachEvents(container);
}
if(container.childNodes)
for(varj=0;j<container.childNodes.length;j++){
varchild=container.childNodes[j];
_self._attach(child);
}
}
}
this._attachEvents=function(obj){
varvalidatorNames=(obj.validator.trim()).split(/s*,s*/g);
varlen=validatorNames.length;
for(vari=len-1;i>=0;i--){
varvalidatorName=validatorNames[i].toLowerCase();
varvaliatorTypeName=_self._upperFirstLetter(validatorName)+"Validator";
varnamespace=typeof(obj.vnamespace)=='undefined'?"net.bingosoft.web":obj.vnamespace;
if(namespace)valiatorTypeName=namespace+"."+valiatorTypeName;
varfn=Function.parse(valiatorTypeName);
if(!fn){
alert('cannotfindvalidator:'+valiatorTypeName);
}else{
varvalidator=newfn(obj,validatorName);
varevents=validator.getEvents();
if(events){
vararrEvents=events.split(/s*,s*/g);
for(varj=0;j<arrEvents.length;j++){
obj.attachEvent(arrEvents[j],validator._doValidate);
}
}
}
}
}
this._getNamespace=function(obj,validatorName){
varns=validatorName+"_namespace";
if(obj[ns])returnobj[ns];
if(obj.vnamespace)returnobj.vnamespace;
return"net.bingosoft.web";
}
this._check=function(obj){
varvalidatorNames=(obj.validator.trim()).split(/s*,s*/g);
varlen=validatorNames.length;
for(vari=len-1;i>=0;i--){
varvalidatorName=validatorNames[i].toLowerCase();
varvaliatorTypeName=_self._upperFirstLetter(validatorName)+"Validator";
varnamespace=_self._getNamespace(obj,validatorName);
if(namespace)valiatorTypeName=namespace+"."+valiatorTypeName;
varfn=Function.parse(valiatorTypeName);
if(!fn){
alert('cannotfindvalidator:'+valiatorTypeName);
}else{
varvalidator=newfn(obj,validatorName);
if(!validator._doValidate())returnfalse;
}
}
returntrue;
}
this._upperFirstLetter=function(inputString){
if(!inputString)returninputString;
varfirst=inputString.substring(0,1).toUpperCase();
varleft=inputString.substring(1);
returnfirst+left;
}
this.validate=function(){
if(arguments.length>0){
_self._validate(arguments[0]);
}else{
return_self._validate(_containers);
}
}
this._validate=function(obj){
if(!obj)returntrue;
if(!(objinstanceofArray))obj=[obj];
for(vari=0;i<obj.length;i++){
varcontainer=obj[i];
if(container.validator){
if(!_self._check(container))returnfalse;
}
if(container.childNodes)
for(varj=0;j<container.childNodes.length;j++){
varchild=container.childNodes[j];
if(!_self._validate(child))returnfalse;
}
}
returntrue;
}
}
net.bingosoft.web.Validators.registerSealedClass("net.bingosoft.web.Validators",null,null);
net.bingosoft.web.Validators._attachBodyReadyState=function(){
if(document.readyState=="complete"){
window.$validator=newnet.bingosoft.web.Validators();
window.$validator.attach();
}
}
document.attachEvent("onreadystatechange",net.bingosoft.web.Validators._attachBodyReadyState);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//{validator}_message
//{validator}_namespace
//{validator}_events
//vmessage
//vnamespace
//venvents
//vrealtime
net.bingosoft.web.Validator=function(element,validatorName){
net.bingosoft.web.Validator.initializeBase(this);
var_element=element;
if(!_element)thrownewError("cannotfoundhtmlelement!");
if(!validatorName)thrownewError("cannotfoundparam'validatorName'");
if(typeof(_element.validate_next)=='undefined'){
_element.validate_next=true;
//_element.style.backgroundColor="blue";
}
var_validatorName=validatorName;
本文地址:http://www.45fan.com/dnjc/67081.html