//辅助js //获取url参数 function querystring(name) { var reg = new regexp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeuricomponent(r[2]); return ""; } //替换url参数 string.prototype.replaceparam = function (param, value) { var url = this; var pattern = param + '=([^&]*)'; var replacetext = param + '=' + value; if (url.match(pattern)) { var tmp = '/(' + param + '=)([^&]*)/gi'; tmp = url.replace(eval(tmp), replacetext); return tmp; } else { if (url.match('[\?]')) { return url + '&' + replacetext; } else { return url + '?' + replacetext; } } return url + '\n' + param + '\n' + value; } //在图片名称前加入一个字符,得到缩略图的地址 function smallimagefilepath(imagefile, smallstring) { var stem = ""; if ($.trim(imagefile) != "") { var str = imagefile.split("/"); for (var i = 0; i < str.length; i++) { //最后一个 if (str.length != 0 && i == str.length - 1) { stem += smallstring + str[i]; } else { stem += str[i] + "/"; } } } return stem; } //字符串转时间 string.prototype.todate = function () { var str = this.replace("t", " ").replace(new regexp("-", "gm"), "/"); if (str.indexof(".") != -1) str = str.substr(0, str.indexof(".")); return new date(str); } //设置时间format date.prototype.format = function (format) { /* * eg:format="yyyy-mm-dd hh:mm:ss"; */ var o = { "m+": this.getmonth() + 1, // month "d+": this.getdate(), // day "h+": this.gethours() % 12 == 0 ? 12 : this.gethours() % 12, //hour "h+": this.gethours(), // hour "m+": this.getminutes(), // minute "s+": this.getseconds(), // second "q+": math.floor((this.getmonth() + 3) / 3), // quarter "s": this.getmilliseconds() // millisecond }; if (/(y+)/.test(format)) { format = format.replace(regexp.$1, (this.getfullyear() + "").substr(4 - regexp.$1.length)); } for (var k in o) { if (new regexp("(" + k + ")").test(format)) { format = format.replace(regexp.$1, regexp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); } } return format; }; //设置cookie function setcookie(cname, cvalue, date) { if (date) { var d = new date(); d.setdate(d.getdate() + date); var expires = "expires=" + d.togmtstring(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;"; } else { document.cookie = cname + "=" + cvalue + ";path=/;"; } } //读取cookie function getcookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i].trim(); if (c.indexof(name) == 0) return c.substring(name.length, c.length); } return null; } //删除cookie function delcookie(name) { var exp = new date(); exp.settime(exp.gettime() - 1); var cval = getcookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.togmtstring() + ";path=/;"; } //html编码/解码 function htmlencode(str) { var t = document.createelement("div"); t.textcontent ? t.textcontent = str : t.innertext = str; return t.innerhtml; } function htmldecode(str) { var t = document.createelement("div"); t.innerhtml = str; return t.innertext || t.textcontent; } //过滤json特殊字符 function filterjson(str) { return str.replace(new regexp("\\", "gm"), "\\\\").replace(new regexp("\"", "gm"), "\\\"").replace(new regexp("\n", "gm"), "\\n").replace(new regexp("\r", "gm"), "\\r"); } function filterjson2(str) { return str.replace(new regexp("\\\"", "gm"), "\"").replace(new regexp("\\\\", "gm"), "\\").replace(new regexp("\\n", "gm"), "\n").replace(new regexp("\\r", "gm"), "\r"); } //复制字符串 function copystr(str) { var $str = $("").appendto("body").select(); document.execcommand("copy"); $str.remove(); top.layer.msg("复制成功!", { icon: 6 }); } //获取表单数据 function getformdata(obj) { var formobj = obj ? obj : $("form"); //对编辑器内容进行转码 formobj.find("textarea.richeditor_editor").each(function () { $(this).val(encodeuricomponent(tinymce.editors[$(this).attr("name")].getcontent())); }) formobj.find("textarea.codemirror_editor").each(function () { $(this).val(encodeuricomponent(eval("(" + $(this).attr("name") + "_editor.getvalue())"))); }) var formdata = {}; var fieldelem = formobj.find("input,select,textarea"); //获取所有表单域 fieldelem.each(function () { if (!this.name) return; if (/^checkbox|radio$/.test(this.type) && !this.checked) return; if (!formdata[this.name]) formdata[this.name] = $(this).attr("encoding") != undefined ? encodeuricomponent($(this).val()) : $(this).val(); }) return formdata; } function ajaxhelper(url, data, successcallback) { $.ajax({ type: "post", url: url, data: data, headers: { token: $("#token").val() }, success: function (data, textstatus) { if (successcallback) successcallback(data, textstatus); }, error: function (xmlhttprequest, textstatus, errorthrown) { layer.closeall("loading"); } }); } //ajax提交 function ajaxsubmit(url, successcallback) { ajaxhelper(url, getformdata(), successcallback); } //ajax操作执行提示 function ajaxprompt(url, data, options) { layer.load(1); ajaxhelper(url, data, function (data) { try { var res = json.parse(data); if (!options) options = {}; //若未自定义成功提示,则采用默认设置 if (!options["1"]) { options["1"] = function () { top.layer.msg(res.msg, { icon: 6 }); } } //若未自定义失败提示,则采用默认设置 if (!options["-1"]) { options["-1"] = function () { top.layer.msg(res.msg, { icon: 5 }); } } //执行提示 if (options[res.flag]) { options[res.flag](res); } else { //其他提示 top.layer.msg(res.msg, { icon: 7 }); } } catch (e) { $("body").append(data); } layer.closeall("loading"); }); } //加法 function add(a, b) { var c, d, e; try { c = a.tostring().split(".")[1].length; } catch (f) { c = 0; } try { d = b.tostring().split(".")[1].length; } catch (f) { d = 0; } return e = math.pow(10, math.max(c, d)), (mul(a, e) + mul(b, e)) / e; } //减法 function sub(a, b) { var c, d, e; try { c = a.tostring().split(".")[1].length; } catch (f) { c = 0; } try { d = b.tostring().split(".")[1].length; } catch (f) { d = 0; } return e = math.pow(10, math.max(c, d)), (mul(a, e) - mul(b, e)) / e; } //乘法 function mul(a, b) { var c = 0, d = a.tostring(), e = b.tostring(); try { c += d.split(".")[1].length; } catch (f) { } try { c += e.split(".")[1].length; } catch (f) { } return number(d.replace(".", "")) * number(e.replace(".", "")) / math.pow(10, c); } //除法 function div(a, b) { var c, d, e = 0, f = 0; try { e = a.tostring().split(".")[1].length; } catch (g) { } try { f = b.tostring().split(".")[1].length; } catch (g) { } return c = number(a.tostring().replace(".", "")), d = number(b.tostring().replace(".", "")), mul(c / d, math.pow(10, f - e)); } //四舍五入 function todecimal(num, pos) { return math.round(num * math.pow(10, pos)) / math.pow(10, pos); } //判断是否是数字 function isnumber(str) { return !isnullorempty(str) && !isnan(str.tostring()); } //判断null或空值 function isnullorempty(str) { return str == undefined || str == null || str == '' || str == 'null'; } //前台弹窗 function windowdialog(url, title, width, height) { //计算宽度 if (width.indexof("%") != -1) { width = $(window).width() * parsefloat(width.replace("%", "")) / 100 + "px"; } //计算高度 if (height.indexof("%") != -1) { height = $(window).height() * parsefloat(height.replace("%", "")) / 100 + "px"; } var node = ""; node += "