For details, please see the comments, there are not many BBs here.
Provide the code:
/// <reference path="vendor/jquery-1.4.1-vsdoc.js" />//// Verification in the form that cannot be empty (.notnull)/* Time: 2012-6-6 Function: When there are multiple (including one) forms under a pair of form tags that need to be submitted, use js to accurately judge the current button to judge those elements using the current button Usage: find the container of the current form under the form tag to give class="form", and the submit button of the current form to give class="notnull" nullmsg="xx cannot be empty!" prompt, form that needs to be logically judged is given class="need" The type of judgment is given (can only be digits) Verification prompts logicmsg="XX can only be digits" Give class="errorMessage" to display error message block Give class="warn" to display error message without using js object-oriented programming logic judgment, no need identifier is passed in, and the regular expression attribute (custom) is given directly (custom) regex="/^/d$/" is made to implement the Global.submitCallback button callback function externally; Where to improve: No update time: December 3, 2014 16:23:22 Author: Amber.Xu *///$(document).ready(// function () {// $("form").find(".notnull").bind({// focus: function () {// if ($(this).attr("value") == this.defaultValue) {// $(this).attr("value", "");// }// },// },// blur: function () {// if ($(this).attr("value") == "") {// $(this).attr("value", this.defaultValue);// }// });// }// });// }// }// });// }// }//);//* Method to encapsulate a universal detection form*///// event.srcElement: The target object that raises an event, is often used for onclick events. ///event.fromElement: The object source that raises the event, often used in onmouseout and onmouseover events. ///event.toElement: After the event is raised, the target source moved to by the mouse, which is often used for onmouseout and onmouseover events. function Global() { var _self = this;}Global.submitCallback = null;Global.confirmCallback = null;$(document).ready(function () { //form body $("body").find(".form").each(function () { this.onclick = function (e) { var button = null; try { button = e.srcElement == null ? document.activeElement : e.srcElement; } catch (e) { console.log(e.message) button = document.activeElement; } if ($(button).is(".check")) { //alert("Submit") var sub = (checkform(this) && CheckInputRex(this) && checkselect(this) && checkChecked(this)); if (sub) { // Call our callback, but using our own instance as the context Global.submitCallback.call(this, [e]); } return sub; } else if ($(button).is(".confirm")) { //alert("Delete") var sub = confirm($(button).attr("title")); if (sub) { Global.confirmCallback.call(this, [e]); } return sub; } else { // //alert("other") return true; } } }); /*Detection elements that cannot be empty in the form*/ function checkform(form) { var b = true; $(form).find(".notnull").each(function () { if ($.trim($(this).val()).length <= 0) {//|| $(this).val() == this.defaultValue // if (this.value != null) { // $(this).attr("value", ""); // } //alert($(this).attr("msg")) $(this).parents(".form").find(".warn").text($(this).attr("nullmsg")); $(this).parents(".form").find(".errorMessage").show(); $(this).select(); $(this).focus(); return b = false; } }); if (b == true) { $(form).find(".warn").text(""); $(form).find(".errorMessage").hide(); } return b; } /*The required drop-down list in the detection form*/ function checkselect(form) { var b = true; $(form).find(".select").each(function (i) { var ck = $(this).find('option:selected').text(); if (ck.indexOf("Select") > -1) { $(this).parents(".form").find(".warn").text($(this).attr("nullmsg")); $(this).parents(".form").find(".errorMessage").show(); $(this).select(); $(this).focus(); return b = false; } }); return b; } /*Responsible checkbox in the form*/ function checkChecked(form) { var b = true; $(form).find(".checkbox").each(function (i) { var ck = $(this)[0].checked; if (!ck) { $(this).parents(".form").find(".warn").text($(this).attr("nullmsg")); $(this).parents(".form").find(".errorMessage").show(); $(this).select(); $(this).focus(); return b = false; } }); return b; } //Check whether the regular expression matches function GetFlase(value, reg, ele) { if (reg.test(value))) { return true; } $(ele).parents(".form").find(".warn").text($(ele).attr("logicmsg")); $(ele).parents(".form").find(".errorMessage").show(); $(ele).focus(); $(ele).select(); return false; //Cannot submit} function CheckInputRex(form) { var b = true; $(form).find("input[type='text']").each(function () { if (typeof ($(this).attr("regex")) == 'string') { if ($.trim($(this).val()).length > 0 && $(this).val() != this.defaultValue) { //The current form's value var value = $(this).attr("value") || $(this).val(); var regx = eval($(this).attr("regex")); return b = GetFlase(value, regx, this); } } }); return b; } ///Check whether the corresponding character entered by the user is legal///This method has been deprecated function CheckInput(form) { var b = true; $(form).find(".need").each(function () { if ($.trim($(this).val()).length > 0 && $(this).val() != this.defaultValue) { //The current form value var value = $(this).attr("value"); //The value of id or the value of the attribute of name is as follows: [name="contact"] var name = $(this).attr("class"); //Check whether the content to be entered is legal, such as: Contact information var len = name.split(" "); for (var i = 0; i < len.length; i++) { switch ($.trim(len[i])) { ///Contact information case "mobile": var reg = /^1/d{10}$/; return b = GetFlase(value, reg, this); break; ///Email case "email": var reg = /^[/w-]+(/.[/w-]+)*@[/w-]+(/.[/w-]+)+$/; return b = GetFlase(value, reg, this); break; ///Do the passwords are the same as the two times case "password": break; case "password2": if ($("#password").attr("value") != $("#password2").attr("value")) { $(this).select(); //Get focus $(this).parents(".form").find(".warn").text($(this).attr("logicmsg")); $(this).parents(".form").find(".errorMessage").show(); return b = false; //Cannot submit} break; case "worktel": case "hometel": //Home phone var reg = /^/d{8}$/; return b = GetFlase(value, reg, this); break; case "post": //Zip code var reg = /^/d{6}$/; return b = GetFlase(value, reg, this); break; case "bonus": case "allowance": case "FixedSalary": var reg = /^-?([1-9]/d*/./d*|0/./d*[1-9]/d*|0?/.0+|0|[1-9]/d)$/; return b = GetFlase(value, reg, this); break; case "identity": var reg = /(^/d{15}$)|(^/d{18}$)|(^/d{17}(/d|X|x)$)/; return b = GetFlase(value, reg, this); break; case "height": var reg = /^[1-2][0-9][0-9]$/; return b = GetFlase(value, reg, this); break; case "qq": var reg = /^[1-9][0-9]{4,}$/; return b = GetFlase(value, reg, this); break; case "begintime": case "endtime": var reg = /^/d{4}$/; if (reg.test(value) && (parseInt($(".endtime").val())) > parseInt($(".begintime").val()))) { return b; } $.ligerDialog.alert($(this).attr("msg")) $(this).select(); //Get focus return b = false; //Cannot submit break; case "num": var reg = /^/d+$/; return b = GetFlase(value, reg, this); break; ///To go to Hong Kong to Hong Kong, mainland China needs to apply for a pass to Hong Kong and Macau and Hong Kong visa. The format of private ordinary passport number is: ///14/15+7 digits, G+8 digits; ///On the business is: P.+7 digits; ///On the business is: S.+7 digits or //S+8 digits, and the diplomatic passport case "postport": //Passport number var reg = /^(P/d{7}|G/d{8}|S/d{7,8}|D/d+|1[4,5]/d{7})$/; return b = GetFlase(value, reg, this); break; case "bankaccount": var reg = /^[0-9]{19}$/; return b = GetFlase(value, reg, this); break; } //switch } //for } }); return b; } ///This method is deprecated});///Click to change the background color $(document).ready(function () { var inputs = $("#top>.c>input"); $(inputs).each(function () { this.onclick = function () { document.getElementById("main").style.backgroundColor = this.name; //$("#main").backgroundColor = this.name; } });});Basically, all commonly used functions are included, I hope you can like it.