js利用apply(), Math object, js数组,对象完全智能验证

注:主要功能就是监听你的错误,哪里有错误就滑到哪里去提示,并且速度可设置,超级人性化,但是错误绑定是必须有id属性的,id作为你验证的唯一身份证, 因为在项目中用到了所以临时挑拣出来的代码,比如监听事件哪里应当封装,加上特殊验证类等,时间问题回头再弄,以下如有问题请留言 :

下载地址:点击打开链接

列出两个类,演示就不列了因为实在样式太不好看了!


/**
*error store class
*/
var Errortop = {
	setErrorTop:function (_this){   
		var height = jQuery(_this).offset().top;
		validateExam.put(height, height, jQuery(_this).attr('id'));
	},

	getErrorTopTip:function (min,time){ 
			if(validateExam.keys.length > 0){
		var maxhight = Math.max.apply(null,validateExam.keys); 
				jQuery('html,body').animate({scrollTop:maxhight-min},time);   // alert(validateExam.obj[maxhight]);
				jQuery("#"+validateExam.obj[maxhight]).focus().css('borderColor', 'red');
			}
	},

	remove:function(id){
		validateExam.remove(id);
	}
}


/**
*error collection class
*/
function CollectionError ()  {
 this.keys = new Array();
 this.data = new Array();
 this.obj = new Array();
 this.distinct = new Array();

 this.put = function (key,value,id){
  if (this.data[key] == null){
   this.keys.push (key); 
	 this.data[key] = value;
	 this.obj[key] = id;
	 this.distinct[id] = key;  
  }
 };


 this.get = function (key){
	return this.data[key];
 };

 this.indexOf = function(val) {
	for (var i = 0; i < this.keys.length; i++) {
			if (this.keys[i] == val) return i;
	}
	return -1;
 };

 this.removekey = function(val) {
	var index = this.indexOf(val);
	if (index > -1) {
			this.keys.splice(index, 1);
	}
 };

 this.remove = function (id){
	if(this.distinct[id] != null){  
		var key = this.distinct[id];
		this.distinct[id] = null;
		this.removekey(key);
		this.data[key] = null;
		this.obj[key] = null;
	}
 };

 this.size = function  ()  {
  return this.keys.length;
 };
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值