Some of the public JS that will be used recently will continue to be supplemented.
String extensions (function () {var fn = String.prototype; Fn.format = function () {var args = arguments; Return This.replace (/\{(\d+) \}/g, function (M, i) {return args[i] | | ""; }); }})();
String formatting "Name:{0},value:{1}". Format ("P0", "P1"): "Name:p0,value:p1"
JSON transform
(function (WD) { var transform = function (oldobj, prefix, Subobjorvalue, includefunc) { if (Subobjorvalue = = null) { Oldobj[prefix] = null; &N Bsp } else { if (subobjorvalue instanceof Array) { for (var i = 0; i < subobjorvalue.length; i++) { & nbsp var Newpex = prefix + "[" + i + "]"; TR Ansform (Oldobj, Newpex, Subobjorvalue[i], Includefunc); } &NB Sp } else if (typeof subobjorvalue = = = "Object") { &NBSP ; for (var name in Subobjorvalue) { if (subobjor Value.hAsownproperty (name)) { var Newobjpex = ""; if (prefix.length = = = 0) { &N Bsp NEWOBJPEX = name + ""; &N Bsp } else { &N Bsp Newobjpex = prefix + "." + name; } T Ransform (Oldobj, Newobjpex, Subobjorvalue[name], Includefunc); &NB Sp } } } else { if (includefunc) { &NBSP ; Oldobj[prefix] = subobjorvalue; } else { if (typeof subobjorvalue!== "function") { &N Bsp Oldobj[prefix] = subobjorvalue; } } & nbsp } } } WD. Json.__transformtosimple = function (jsonobj, prefix, includefunc) { if (!jsonobj) { &nbs P return null; } var obj = {};   ; transform (obj, prefix | | "", Jsonobj, Includefunc);nbsp return obj; };}) (window); The JSON in JS is converted to simple JSON, multiple levels of JSON, converted to only one level of JSON, easy to simulate form submission.
{"A": "V-1", "B": {"b-1": "V-b1", "b-2": "V-b2"}, "C": ["V-c1", "V-C2"]}
Converted to
{"A": "V-1", "b.b-1": "V-b1", "b.b-2": "V-b2", "c[0]": "V-c1", "c[1]": "V-C2"}
HTML encode or decode (function (wd) { Wd.__htmlencode = function (str) { return ("" + str). Replace (/&/g, "&") . Replace (/>/g, ">") . Replace (/</g, "<") . Replace (//g, " ") . replace (/\ '/g, "'") . replace (/\ "/g," "& Amp;quot; "); }; Wd.__htmldecode = function (str) { return ("" + str). Replace (/&am P;amp;/g, "&") . Replace (/>/g, ">") &NBSP ; Replace (/</g, "<") . Replace (/ /g, "") &N Bsp replace (/'/g, "\ '") . Replace (/"/g, "\"); &nbsP };}) (window);
HTML encoding, the special symbols in the HTML code, to prevent interference damage to normal HTML.
JS Common Code Snippets