锘?/杈呭姪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缂栫爜/瑙g爜 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.UEditor_editor").each(function () { $(this).val(encodeURIComponent(UE.getEditor($(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 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 += "
"; node += "
"; node += "
"; node += "
"; node += ""; //璁剧疆鏍囬 if (title) { node += "
" + title + "
"; } node += "
"; node += ""; node += "
"; node += "
"; node += "
"; node += "
"; node += "
"; $("body").append(node); //娣诲姞鍏抽棴浜嬩欢 $(".popMid .close").click(function () { $(this).closest(".popMid").remove(); }) }