In addition to MooTools's core JS file outside. Customize a JS file External_file.js, as follows:
var editcolorobj;
function Editcolor ()
{
var o = new Object ();
O.oldcolor = ""; Save the old color every time
O.curcolor = "#FF0000"; Default color
O.setbackcolor = function (event) {//Set color
O.cobj = Event.target;
O.cstyle = O.cobj.get ("type");
if (o.cstyle!= "checkbox" && o.cstyle!= "Radio" && o.cstyle!= "button") {
O.oldcolor = O.cobj.getstyle ("Background-color");
O.cobj.setstyle ("Background-color", O.curcolor);
}
};
O.backbackcolor = function (event) {//return original color
O.cobj = Event.target;
O.cstyle = O.cobj.get ("type");
if (o.cstyle!= "checkbox" && o.cstyle!= "Radio" && o.cstyle!= "button") {
O.cobj.setstyle ("Background-color", O.oldcolor);
}
};
O.setcurcolor = function (Paramcolor) {//Set new color
O.curcolor = Paramcolor;
};
Identify objects-input and textarea other than Checkbox,radio,button
O.fullobjes = $$ ("input");
O.fullarea = $$ ("textarea");
O.fullsel = $$ ("select");
O.fullobjes.combine (O.fullarea);//Put textarea in object array
O.fullobjes.combine (O.fullsel);//Put a select in an object array
O.fullobjes.addevent ("Focus", o.setbackcolor);//bind to get focused event
O.fullobjes.addevent ("Blur", o.backbackcolor);//bind loses focus event
return o;
};
var editchangevalue = function (event) {
var obj = Event.target;
var texttype = obj.get ("Texttype");
var ematch = obj.get ("Ematch");
var tag = true;//default validation through
if ($chk (texttype))//Has Texttype property
{
Texttype = Texttype.trim (). toLowerCase ();
var m_match = "";
if (Texttype = = "Number") {
M_match =/^ (-|\+) \d+ (\.\d+) $/;
}else if (texttype = = "int") {//Integer (includes positive integer, negative integer, 0)
M_match =/^ (-?[ 0-9]*[1-9][0-9]*) | (0+)) $/;
}else if (Texttype = = "+int") {//positive integer
M_match =/^[0-9]*[1-9][0-9]*$/;
}else if (Texttype = = "-int") {//negative integer
M_match =/^-[0-9]*[1-9][0-9]*$/;
}else if (Texttype = = "+int0") {//non-negative integer
M_match =/^\d+$/;
}else if (Texttype = = "-int0") {//non-positive integer
M_match =/^ (-[0-9]*[1-9][0-9]*) | ( 0+)) $/;
}else if (Texttype = = "float") {//floating-point number
M_match =/^ ((-?\d+) (\.\d+) | (0) $/;
}else if (Texttype = = "+float") {//positive floating-point number
M_match =/^ (\d+) (\.\d+) $/;
}else if (Texttype = = "-float") {//negative floating-point number
M_match =/^ (-\d+) (\.\d+) $/;
}else if (Texttype = = "+float0") {//non-negative floating-point number
M_match =/^ ((\d+) (\.\d+) | (0) $/;
}else if (Texttype = = "-float0") {//non-positive floating-point number
M_match =/^ ((-\d+) (\.\d+) | (0) $/;
}else if (Texttype = = "Date") {//Date time
M_match =/^ (\d{2} ([02468][048]) | ( [13579] [26])) [\-\/\s]? (((0? [13578]) | (1[02]) [\-\/\s]? ((0?) [1-9]) | ([1-2][0-9]) | (3[01])) | ((0? [469]) | (11)) [\-\/\s]? ((0?) [1-9]) | ([1-2][0-9]) | (30)) | (0?2[\-\/\s]? ((0?) [1-9]) | ([1-2][0-9])) | (\d{2} ([02468][1235679]) | ( [13579] [01345789])) [\-\/\s]? (((0? [13578]) | (1[02]) [\-\/\s]? ((0?) [1-9]) | ([1-2][0-9]) | (3[01])) | ((0? [469]) | (11)) [\-\/\s]? ((0?) [1-9]) | ([1-2][0-9]) | (30)) | (0?2[\-\/\s]? ((0?) [1-9]) | (1[0-9]) | (2[0-8])))) /;
}else if (texttype = = "Email") {//email
M_match =/^ ([a-za-z0-9]) (\w) +@ (\w) + (\.) (com|com\.cn|net|cn|net\.cn|org|biz|info|gov|gov\.cn|edu|edu\.cn)/;
}else if (texttype = = "url") {//url
M_match =/^http (s)?: \ /\/([\w\u4e00-\u9fa5-]+\.) +[\w\u4e00-\u9fa5-]+ ((: \d+)?) + (\/[\w\u4e00-\u9fa5-. \?%&=]+) *$/;
}else if (Texttype = = "Phone") {//Landline
M_match =/^ (0[0-9]{2,3}\-?) ([2-9][0-9]{6,7}) + (\-[0-9]{1,4})? $/;
}else if (Texttype = = "Mobil") {//Mobile phone
M_match ==/^[+]{0,1} (\d) {1,3}[]? ([-]? ((\d) | []) {1,12}) +$/;
}else if (Texttype = = "Call") {//landline or cell phone
M_match =/(\d{11}) |^ ((\d{7,8}) | ( \D{4}|\D{3})-(\d{7,8}) | (\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}) | (\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})) $/;
}
Tag =obj.value.test (M_match, "I");
if (!tag) {
Obj.value = "";
return;//returns directly, no longer validates the following regular expression
}
}
if ($chk (Ematch)) {//has Ematch (regular expression) property
try{
Ematch = eval (Ematch.trim ());//eval (Ematch.trim (). Escaperegexp ());
Tag = Obj.value.test (Ematch);
if (!tag) {
Obj.value= "";
}
}catch (e) {}//alert (e);
}
};
Window.addevent (' Domready ', function () {
Set a single page in another color on a page
Window.addevent (' Domready ', function () {
Editcolorobj.setcurcolor ("#FF0000");
//});
Editcolorobj = new Editcolor ()//Page text box or selection box get focus change color
Set Text type
var fullobjes = $$ ("input");
var Fullarea = $$ ("textarea");
Fullobjes.combine (Fullarea);
Fullobjes.addevent ("Change", Editchangevalue)//text content changes, and loss of focus
});