Please see the details of the note, here is not more BB,
The code:
<reference path= "vendor/jquery-1.4.1-vsdoc.js"/>///detect the validation/* time in the form that cannot be empty (. notnull): 2012-6-6
Function: A pair of form labels under a multiple (including a) Form need to submit, use JS accurate to determine the current button on those elements to judge the use: Under the form label to find the current form of the container to give class= "form", the current form of the submit button to give class= "check" The element that needs to be validated as empty gives class= "Notnull" nullmsg= xx cannot be empty!
"Hint, the form that needs to be logically judged gives the class=" need "the type of judgment that gives class=" num "(only a number) validation logicmsg=" XX can only be number "give class=" errormessage "Display error message Block Give class= "warn" Display error message does not use the JS object-oriented programming logic judgment, does not pass in the need identity, directly gives the regular expression attribute (custom) regex= "/^\d$/" to make the judgment in the exterior realization Global.submitcallback
Button callback function Global.confirmcallback confirm callback function; Where to improve: No update time: December 3, 2014 16:23:22 Author: Amber.xu * *//$ (document). Ready (//function () {//$ ("form"). Find (". Notn Ull "). Bind ({//Focus:function () {//if ($ (this). attr (" value ") = = This.defaultvalue) {//$ (this).
attr ("Value", ""); //////Blur:function () {//if ($ (this). attr ("value") = = "") {//$ (this). attr ("
Value ", this.defaultvalue);
// }
// }
// }); // }
//);
* A method of encapsulating a universal detection form////event.srcelement: The target object that raises the event, which is commonly used in the OnClick event.
Event.fromelement: The object source that raises the event, commonly used in onmouseout and onmouseover events.
Event.toelement: The target source that the mouse moves to after the event is raised, and is commonly used in 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 (th
IS) && Checkselect (This) && checkchecked (this); if (sub) {//Call we 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;
}
}
});
/* Detect the element that cannot be empty in the form/function Checkform (form) {var b = true; $ (form). Find ('. Notnull '). each (function () {if ($.trim (). Val ()). Length <= 0} {//| | $ (This). val () = This.de
Faultvalue//if (This.value!= null) {//$ (this). attr ("Value", ""); }//alert ($ (this). attr ("MSG") $. 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 (the 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;
/* * Check the required checkbox in the form/function checkchecked (form) {var b = true;
$ (form). Find ('. CheckBox '). each (the 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 to match the regular expression 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 commit} 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) {//current form value Var Valu E = $ (this). attr ("value") | |
$ (this). Val ();
var regx = eval ($ (this). attr ("regex"));
return B = getflase (value, REGX, this);
}
}
});
return b;
///check that the appropriate characters entered by the user are legitimate///This method has deprecated function checkinput (form) {var b = true; $ (form). Find ('. Need '). each (function () {if ($.trim (). Val ()). length > 0 && $ (this). Val ()!= this.de
Faultvalue) {//The value of the current form var value = $ (this). attr ("value"); The value of the ID or the value of the attribute of name, such as: [NAMe= ' contact '] var name = $ (this). attr ("class");
Check if the content you want to enter is legal such as: Contact method var len = Name.split ("");
for (var i = 0; i < len.length i++) {switch ($.trim (len[i)) {///Contact
Case "mobile": var reg =/^1\d{10}$/;
return B = getflase (value, Reg, this);
Break Mailbox Case "Email": Var reg =/^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[
\w-]+) +$/;
return B = getflase (value, Reg, this);
Break Two times password is consistent case "password": Bre
Ak Case "Password2": if ($ ("#password"). attr ("value")!= $ ("#password2"). attr ("value")) {$ (thi s). 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"://Postal 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 ())) {RET
Urn 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
Mainland China is required to transact Hong Kong-Macau pass and Hong Kong's endorsement. Due to private ordinary passport number format:///14/15+7 digits, g+8 digits; Because the common is: p.+7 number of digits;///business is: s.+7 digits or
S+8 digits, starting with D is 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 has been discarded});
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;
}
});
});
The
Most commonly used features are encapsulated in the hope that the small partners can enjoy.