1. 格式化 format
function format(string) { var args = arguments; var pattern = new RegExp(“%([1-" + arguments.length + "])”, ”g”); return String(string).replace(pattern, function(match, index) { return args[index]; }); };//调用 format(“And the %1 want to know whose %2 you %3″, ”papers”, ”shirt”, ”wear”);//上面的代码将返回:And the papers want to know whose shirt you wear"
2. 获取GUID
function guidGenerator() { var S4 = function() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); }; return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());}
3.getQuerystring
JS={};JS.getQueryString = function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }