Copy codeThe Code is as follows:
/*
* Copyright VeryIDE, 2007-2008
* Http://www.veryide.com/
*
* $ Id: veryide. library. js, v2.3 leilei $
*/
Function $ (obj) {return document. getElementById (obj );}
Function $ N (obj) {return document. getElementsByName (obj );}
Function $ T (obj) {return document. getElementsByTagName (obj );}
Function $ V (str) {document. write (str );}
// Body load
Function addLoadEvent (func ){
Var oldonload = window. onload;
If (typeof window. onload! = 'Function '){
Window. onload = func;
} Else {
Window. onload = function (){
Oldonload ();
Func ();
}
}
}
// Object event
Function addObjectEvent (ele, evt, func ){
Var oldonevent = ele ['on' + evt];
If (typeof ele ['on' + evt]! = 'Function '){
Ele ['on' + evt] = func;
} Else {
Ele ['on' + evt] = function (event ){
Oldonevent (event );
Func (event );
}
}
}
// Key event
Function addKeyEvent (key, func ){
If (! VeryIDE. tmpKey ){
VeryIDE. tmpKey = [];
}
VeryIDE. tmpKey ["k" + key] = func;
}
AddKeyEvent. Listener = function (e, test ){
Var event = e | window. event;
If (VeryIDE. tmpKey ["k" + event. keyCode]) {
VeryIDE. tmpKey ["k" + event. keyCode] (event );
}
If (test ){
Alert (event. keyCode );
}
}
// Onkeydown determines charCode/keyCode
// Obtain the object
Function getObject (o ){
If (typeof (o )! = "Object "){
Var o = $ (o );
}
Return o;
}
/*
String. prototype. trim = function (){
Return this. replace (/(^ \ s +) | \ s + $/g ,"");
}
*/
String. prototype. Trim = function (){
Return this. replace (/(^ \ s *) | (\ s * $)/g ,"");
}
String. prototype. LTrim = function (){
Return this. replace (/(^ \ s *)/g ,"");
}
String. prototype. Rtrim = function (){
Return this. replace (/(\ s * $)/g ,"");
}
// Returns the number of bytes of the string.
String. prototype. long = function (){
Var I;
Var l = this. length;
Var len;
Len = 0;
For (I = 0; I <l; I ++ ){
If (this. charCodeAt (I)> 255)
Len + = 2;
Else
Len ++;
}
Return len;
}
// Check whether a value exists in the array
Function inArray (a, v ){
Var l = a. length;
For (var I = 0; I <= l; I ++ ){
If (a [I] = v) return true;
}
Return false;
}
// All elements whose class is *
Document. getElementsByClassName = function (){
Var children = document. getElementsByTagName ('*') | document. all;
Var elements = new Array ();
Var len = children. length;
For (var I = 0; I <len; I ++ ){
Var child = children [I];
Var classNames = child. className. split ('');
For (var j = 0; j <classNames. length; j ++ ){
For (var k = 0; k <arguments. length; k ++ ){
If (classNames [j] = arguments [k]) {
Elements. push (child );
Break;
}
}
}
}
Return elements;
}
// All elements whose IDs start *
Document. getElementsByPrefix = function (prefix ){
Var children = document. getElementsByTagName ('*') | document. all;
Var elements = new Array ();
Var len = children. length;
For (var I = 0; I <len; I ++ ){
Var child = children [I];
Var eid = child. id;
If (eid & eid. indexOf (prefix)>-1)
Elements. push (child );
}
Return elements;
}
/* Search for the page Meta */
Function getMeta (name, att ){
Required AGS = document. getElementsByTagName ("meta ");
For (cnt = 0; cnt <symbol AGS. length; cnt ++ ){
If (cmdags [cnt]. getAttribute ("name") = name ){
If (! Att ){
Return required AGS [cnt];
} Else {
Return destination AGS [cnt]. getAttribute (att );
}
} Else {
Return null;
}
}
}
// Load the new script
Function loadScript (src, target ){
If (! Target ){
Var root = $ T ("HEAD") [0];
} Else {
Var root = getObject (target );
}
Var script = document. createElement ("script ");
Script. type = "text/javascript ";
Script. src = src;
Var code = arguments [2];
If (code ){
Script. charset = code;
}
Root. appendChild (script );
}
// Get the file name
Function getFileName (url ){
Var strUrl = location. href;
If (url ){
StrUrl = url;
}
Var arrUrl = strUrl. split ("/");
Var strPage = arrUrl [arrUrl. length-1];
Return strPage;
}
// Absolute object location
Function getPosition (obj ){
Var obj = getObject (obj );
This. width = obj. offsetWidth;
This. height = obj. offsetHeight;
This. top = obj. offsetTop;
This. left = obj. offsetLeft;
While (obj = obj. offsetParent ){
This. top + = obj. offsetTop;
This. left + = obj. offsetLeft;
}
}
Function getSelect (obj ){
Var obj = getObject (obj );
This. value = "";
This. text = "";
This. index = "";
If (obj. length> 0 ){
This. value = obj [obj. selectedIndex]. value;
This. text = obj [obj. selectedIndex]. text;
This. index = obj. selectedIndex;
}
This. getAtt = function (att ){
Return obj [obj. selectedIndex]. getAttribute (att );
}
}
//
Function getRadio (obj ){
Var obj = $ N (obj );
Var len = obj. length;
This. value = "";
For (var I = 0; I <len; I ++ ){
If (obj [I]. checked = true ){
This. value = obj [I]. value;
Break;
}
}
}
// Hide object display
Function showHide (obj ){
Var obj = getObject (obj );
If (obj ){
If (obj. offsetHeight = 0 | obj. style. display = "none") {obj. style. display = "block";} else {obj. style. display = "none ";}
}
}
Function setCheckBox (obj, v ){
Var obj = $ N (obj );
If (obj [0]) {
Var len = obj. length;
For (var I = 0; I <len; I ++ ){
If (obj [I]. value = v ){
Obj [I]. checked = true;
} Else {
Obj [I]. checked = false;
}
}
} Else {
Obj = $ (obj );
If (obj. value = v ){
Obj. checked = true;
} Else {
Obj [I]. checked = false;
}
}
}
// Select a list item
Function setSelect (obj, v ){
Var obj = $ (obj );
Var len = obj. length;
For (var I = 0; I <len; I ++ ){
If (obj [I]. value = v ){
Obj. selectedIndex = I;
Break;
}
}
}
// Select a single option
Function setRadio (o, v ){
Var obj = $ N (o );
Var len = obj. length;
For (var I = 0; I <len; I ++ ){
If (obj [I]. value = v ){
Obj [I]. checked = true;
Break;
}
}
}
// Disable the object
Function setDisabled (obj, B ){
Var obj = getObject (obj );
If (obj) {obj. disabled = B ;}
}
Function setClass (obj, Class, Type ){
Var obj = getObject (obj );
If (obj ){
Switch (Type ){
Case "+ ":
Obj. className + = "" + Class;
Break;
Case "-":
Obj. className = obj. className. replace (Class ,"");
Break;
Case "":
Obj. className = Class;
Break;
}
}
}
// Create a continuous downlink list item
Function newNumOption (obj, s, e, t ){
Var obj = getObject (obj );
If (t = "new") {obj. length = 0 ;}
For (var I = s; I <(e + 1); I ++ ){
Obj. options [obj. length] = new Option (I, I );
}
}
// Delete an object
Function delElement (obj ){
Var obj = getObject (obj );
Var p = obj. parentNode;
P. removeChild (obj );
}
// Confirm the operation
Function getConfirm (info ){
If (! Confirm (info) {return false}
}
// Open a link in a new window
// Rel = "_ blank"
Function _ blank (){
Var anchors = document. getElementsByTagName ("");
Var len = anchors. length;
For (var I = 0; I <len; I ++ ){
Var anchor = anchors [I];
If (anchor. getAttribute ("href") & anchor. getAttribute ("rel") = "_ blank "){
Anchor.tar get = "_ blank ";
}
}
}
// Obtain URL parameters
Function getQuery (n, url ){
If (! Url ){
Var url = location. href;
}
Var v = '';
Var o = url. indexOf (n + "= ");
If (o! =-1 ){
O + = n. length + 1;
E = url. indexOf ("&", o );
If (e =-1 ){
E = url. length;
}
V = unescape (url. substring (o, e ));
}
// Seo
If (! V ){
Var o = url. indexOf (n + "-");
If (o! =-1 ){
O + = n. length + 1;
E = url. indexOf ("-", o );
If (e =-1 ){
E = url. length;
}
V = unescape (url. substring (o, e ));
}
}
Return v;
}
// Convert the fullwidth to halfwidth
Function switchChar (str ){
Var str1 = "1234567890 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
Var str2 = "1234567890 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
Var len = str. length;
For (var I = 0; I <len; I ++ ){
Var n = str2.indexOf (str. charAt (I ));
If (n! =-1) str = str. replace (str. charAt (I), str1.charAt (n ));
}
Return str;
}
/*
Obtain random characters
***********
Len Length
Upper case letter for vUpper
Whether vLower is a lowercase letter
Number of vNum
*/
Function getRnd (len, vUpper, vLower, vNum ){
Var seed_array = new Array ();
Var seedary;
Seed_array [0] = ""
Seed_array [1] = "a B c d e f g h I j k l m n o p q r s t u v w x y z ";
Seed_array [2] = "a B c d e f g h I j k l m n o p q r s t u v w x y z ";
Seed_array [3] = "0 1 2 3 4 5 6 7 8 9 ";
If (! VUpper &&! VLower &&! VNum) {vUpper = true; vLower = true; vNum = true ;}
If (vUpper) {seed_array [0] + = seed_array [1];}
If (vLower) {seed_array [0] + = "" + seed_array [2];}
If (vNum) {seed_array [0] + = "" + seed_array [3];}
Seed_array [0] = seed_array [0]. split ("");
Seedary = "";
For (var I = 0; I <len; I ++ ){
Seedary + = seed_array [0] [Math. round (Math. random () * (seed_array [0]. length-1)]
}
Return (seedary );
}
/*
Obtain cookies
Name cookie name
Sub-cookie name
*/
Function getCookie (name, sub ){
Var str = "";
Var arr = document. cookie. replace (/% 25/g, "% "). replace (/% 5F/g ,"_"). match (new RegExp ("(^ |)" + name + "= ([^;] *) (; | $ )"));
If (arr! = Null ){
Try {
Str = decodeURIComponent (arr [2]);
} Catch (e ){
Str = arr [2];
}
}
If (sub ){
If (str ){
Var nSubValueBegin = str. indexOf (sub + "= ");
} Else {
Var nSubValueBegin =-1
}
If (nSubValueBegin! =-1 ){
Var nSubValueEnd = str. indexOf ("&", nSubValueBegin );
If (nSubValueEnd =-1)
NSubValueEnd = str. length;
Var sSubValue = str. substring (nSubValueBegin + sub. length + 1, nSubValueEnd); // obtain the specified subkey Value
Str = sSubValue;
} Else {
Str = "";
}
}
Return str;
}
Function setCookie (key, value, iExpireDays, domain ){
Var cookies = key. replace ("_", "% 5F") + "=" + encodeURIComponent (value) + ";";
If (iExpireDays ){
Var dExpire = new Date ();
DExpire. setTime (dExpire. getTime () + parseInt (iExpireDays * 24*60*60*1000 ));
Cookies + = "expires =" + dExpire. toGMTString () + ";";
}
If (domain ){
Cookies + = "domain =" + domain + ";";
}
Cookies + = "path = /;";
Document. cookie = cookies;
}
/* State */
VeryIDE. script ["library"] = true;