Error:function (msg) {//Declaration error
Throw msg;
},
Parsejson:function (data) {//convert string to JSON format
if (typeof data!== "string" | | |!data) {//first to determine if it exists, whether it is a string
return null;
}
data = Jquery.trim (data);//Remove blank before and after
if (window. JSON && windows. Json.parse) {//Advanced version has native JSON conversion function Window.json
return window. Json.parse (data);
}
if (Rvalidchars.test data.replace (Rvalidescape, "@")//
. replace (Rvalidtokens, "]")//
. replace (Rvalidbraces, "")) {//For simple inspection, {true:1},{' a ', {}}} .... All through
Rvalidchars =/^[\],:{}\s]*$/,
Rvalidescape =/\\ (?: [\\\/bfnrt]|u[0-9a-fa-f]{4})/g,u[0-9a-fa-f]{4} match Chinese and English and escape characters
Rvalidtokens =/"[^" \\\n\r]* "|true|false|null|-?\d+" (?: \. \d*)? (?: [ee][+\-]?\d+)?/g,//matching string does not contain "\ \", "\ n", "\ R", Boolean, NULL, numeric
Rvalidbraces =/(?: ^|:|,) (?: \ s*\[) +/g, matching (start with empty or: or,) (followed by 0 or more spaces, followed by [) as [,: [,,,, [etc.
Return (The New Function ("return" + Data)) ();
}
Jquery.error ("Invalid JSON:" + data);
},
Parsexml:function (data, XML, TMP) {does not understand the use of incoming XML TMP
if (window. Domparser) {//Standard
The Domparser object parses the XML text and returns an XML Document object. To use Domparser, instantiate it with a constructor that takes no arguments, and then call its//parsefromstring () method:
TMP = new Domparser ();
XML = tmp.parsefromstring (data, "text/xml");
else {//IE
XML = new ActiveXObject ("Microsoft.XMLDOM");
Xml.async = "false";
Xml.loadxml (data);
}
TMP = xml.documentelement;
if (! tmp | |! tmp.nodename | | tmp.nodename = = "ParserError") {//judge whether the returned result is empty, is not a node, whether the error
Jquery.error ("Invalid XML:" + data);
}
return XML;
}
Globaleval:function (data) {//Turn data into executable
if (Data && rnotwhite.test (data)) {//Check whether exists, is not empty
(Window.execscript | | function (DATA) {
window["eval"].call (window, data);//window.eval.call (Window,data) This way, Under some circumstances IE can not change the context of the environment so only for IE use Window.execscript, other Rover use Window.eval.call (Window,data);
}) (data);
}
},
Nodename:function (Elem, name) {
return elem.nodename && elem.nodeName.toUpperCase () = = = Name.touppercase ()//To determine whether the node, the section name default is uppercase, in order to ensure that the correct judgment, are converted into the same format (uppercase)
},
Each:function (object, callback, args) {
var name, i = 0,
Length = Object.length,//window,string,function,array type is not undefined;
Isobj = length = = Undefined | | Jquery.isfunction (object);//mainly to partition objects and arrays
if (args) {//If no parameters are passed in, the default name and value are used as arguments, and if there are parameters, the passed arguments are used
if (isobj) {
For (name in object) {
if (callback.apply (object[name], args) = = False) {
Break
}
}
} else {
for (; i < length;) {
if (callback.apply (object[i++], args) = = False) {
Break
}
}
}
else {//If no parameters are passed in,
if (isobj) {
For (the name in object) {//object[name] value as the current object, name and value as arguments
if (Callback.call (object[name, name, object[name]) = = False) {//Judge callback function return value, decide whether to continue looping
Break
}
}
} else {
for (; i < length;) {//object[I] value as the current object, the name (I is ordinal) and value as parameters
if (Callback.call (object[i], I, object[i++]) = = False) {//Judge callback function return value, decide whether to continue looping
Break
}
}
}
}
return object;
},
Trim:trim//Check if there is a native trim method, if the parameter text! = on The intercept before and after the blank, otherwise return empty, there is no original trim, cast to the string and then make a regular replacement, or error, use regular replacement (Trimleft =/^\s+/,//matching left blank, trimright =/\s+$/,//matching right blank),
function (text) {
return text = null?
"" :
Trim.call (text);
} :
function (text) {
return text = null?
"" :
Text.tostring (). Replace (Trimleft, ""). Replace (TrimRight, "");
},