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; };}