Javascript uses apply (), Math object, and js array for completely intelligent object verification.

Source: Internet
Author: User

Note: The main function is to listen to your errors. If there are any errors, the system will slide to the prompt, and the speed can be set, which is super user-friendly, but the error binding must have the id attribute, id is the unique id card for your verification. Because code is used in the project, such as where the listening event should be encapsulated, and special verification classes should be added, you can get back to the problem of time, if you have any of the following questions, please leave a message: list the two classes and the demonstration will not be listed because the style is too bad to read! [Javascript]/*** 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. da Ta [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. d Istinct [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 ;};}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.