During the work of the javascript tool library used during this period, you can use and write your own code. For more information, see
The Code is as follows:
/*
* YYJ. js mainly provides background application methods
* Currently, Ajax, addLoadEvent, deleteAll, getByClass, $ C (= getByClass), $, yyjtable, setCss, getCss, and iaArray methods are available. Finally,
* The instantiation method YYJ. tick is used to calculate the script running time.
* Version 0.1 -- tianyi yyj
*/
Var YYJ = function (){
Var UniqueInstance;
Function constrotor (){
Return {
// Ajax Method
Ajax: function (method, url, data, success, fail ){
Var isget = method. toLowerCase () = "get ";
Var xmlhttp = window. XMLHttpRequest? New XMLHttpRequest (): new ActiveXObject ("Microsoft. XMLHTTP ");
Xmlhttp. open (method, url, true );
If (! Isget) xmlhttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
Xmlhttp. onreadystatechange = function (){
If (xmlhttp. readyState = 4 ){
If (xmlhttp. status = 200 ){
If (success) success (xmlhttp );
} Else {
If (fail) fail (xmlhttp );
}
}
};
Xmlhttp. send (isget? Null: data );
}, // Ajax
AddLoadEvent: function (func ){
Var oldonload = window. onload;
If (typeof window. onload! = 'Function '){
Window. onload = func;
} Else {
Window. onload = function (){
If (oldonload ){
Oldonload ();
}
Func ();
}
}
}, // AddLoadEvent
DeleteAll: function (checkallbtn, checksomebtn, submitbtn ){
Var checkall = YYJ. $ (checkallbtn );
Var checksome = YYJ. $ (checksomebtn );
Var submit1 = YYJ. $ (submitbtn );
Var checkboxs = (function (){
Var arr = [];
Var check = document. getElementsByTagName ("input ");
For (I = 0; I If (check [I]. getAttribute ("type ")! = "Checkbox ")
Continue;
Arr. push (check [I]);
}
Return arr;
})();
Checkall. onclick = function (){
Checkall. clicked = true;
For (var I = 0; I If (! Checkboxs [I]. checked ){
Checkall. clicked = false;
Break;
}
}
If (! Checkall. clicked ){
For (var I = 0; I Checkboxs [I]. checked = true;
}
} Else {
For (var I = 0; I Checkboxs [I]. checked = false;
}
}
}
Checksome. onclick = function (){
For (var x in checkboxs ){
Checkboxs [x]. checked =! Checkboxs [x]. checked;
}
}
Submit1.onclick = function (){
Var haschecked = false;
Var beSureDel = false;
For (var I = 0; I If (checkboxs [I]. checked ){
Haschecked = true;
Break;
}
}
Haschecked? Function (){
BeSureDel = confirm ("are you sure you want to delete the selected item? ");
} (): Function (){
Alert ("No selected item! ");
BeSureDel = false;
}();
Return beSureDel;
}
}, // Deleteall
GetByClass: function (classname, parent, nodename ){
Var s = (parent | document). getElementsByTagName (nodename | "*");
Return function (){
Var a = [];
For (var I = 0, j = s. length; I If (! S [I]. className) continue;
Var name = "" + s [I]. className + "";
If (name. indexOf ("" + classname + "")! =-1 ){
A. push (s [I]);
}
}
Return;
}();
},
$ C: function (classname, parent, nodename ){
Return YYJ. getByClass (classname, parent, nodename );
}, // GetByClass
$: Function (str ){
Return document. getElementById (str );
}, // GetById
Yyjtable: function (tableId ){
Var tbl = YYJ. $ (tableId );
Var trs = tbl. getElementsByTagName ("tr ");
For (var I = 1; I If (I % 2! = 0 ){
Trs [I]. style. backgroundColor = "# FFFFF0 ";
} Else {
Trs [I]. style. backgroundColor = "white ";
}
Trs [I]. onmouseover = function (){
This. col1 = this. style. backgroundColor;
This. style. backgroundColor = "# FFFACD ";
}
Trs [I]. onmouseout = function (){
This. style. backgroundColor = this. col1;
}
}
}, // Yyjtable
/* Usage
YYJ. setCss ([YYJ. $ ("table1")], {
Color: "red ",
BackgroundColor: "silver"
});*/
SetCss: function (eles, opt ){
If (! Eles |! Opt) return;
If (! Eles. length ){
Throw new Error ("the first parameter of setCss must be an array! ");
}
For (var I = 0; j = eles [I]; I ++ ){
Try {
For (var x in opt ){
J. style [x] = opt [x];
}
} Catch (ex ){}
}
}, // SetCss
/* Usage
Var css = YYJ. getCss (YYJ. $ ("table1"), ["backgroundColor"]);
Alert (css ["backgroundColor"]); */
GetCss: function (ele, opt ){
If (! This. isArray (opt )){
Throw new Error ("the second parameter of getCss must be a string array! ");
}
Var css = {};
For (var I = 0, j = opt. length; I Try {
Css [opt [I] = ele. style [opt [I];
} Catch (ex ){}
}
Return css;
}, // GetCss
IsArray: function (opt ){
Return Object. prototype. toString. call (opt) = "[object Array]"
}
};
}
Function getUniqueInstance (){
If (UniqueInstance ){
Return UniqueInstance;
}
UniqueInstance = constrotor ();
Return UniqueInstance;
}
Return getUniqueInstance ();
}();
// Script execution time
/* Usage
Var ti = new YYJ. ticks ();
Ti. begin ();
Code segment
Ti. end ();
Alert (ti. tick );*/
YYJ. ticks = function (){
Var starttick, stoptick;
Return function (){
This. begin = function (){
Starttick = new Date ();
}
This. end = function (){
Stoptick = new Date ();
This. tick = stoptick-starttick;
}
}
}();