jQuery.ajaxSetup({ headers : { ajax : "true" } }); jQuery.formVal = function(form, others) { form = $(form); var array = form.serializeArray(); var j = array.length; var vals = {}; for ( var i = 0; i < j; i++) { vals[array[i].name] = array[i].value; } if (others) { for ( var i in others) { vals[i] = others[i]; } } return vals; }; jQuery.fillForm = function(form, data, all, except) { if (typeof all == "undefined") { all = true; } if (typeof except == "undefined") { except = []; } var e = {}; for ( var i = 0; i < except.length; i++) { e[except[i]] = true; } $("input,select,textarea", $(form)).each(function(i, node) { node = $(node); var name = node.attr("name"); if (e[name]) { return; } if (all) { node.val(data[name] ? data[name] : ""); } else { if (!node.val()) { node.val(data[name] ? data[name] : ""); } } }); }; ajax = function(url, data, callback, errorback) { if (url.indexOf("?") >= 0) { url = url + "&ts=" + (new Date()).getTime(); } else { url = url + "?ts=" + (new Date()).getTime(); } $.post(url, data, function(result) { if (!(result instanceof Object)) { result = eval("(" + result + ")"); } if (result.hasError) { if (result.errors) { var errors = result.errors.message; var msg = []; if (errors instanceof Object) { for ( var i in errors) { if (errors[i] instanceof Array) { for ( var j = 0; j < errors[i].length; j++) { msg.push(errors[i][j]); } } else { msg.push(errors[i]); } } } else if (errors instanceof Array) { for ( var i = 0; i < errors.length; i++) { msg.push(errors[i]); } } else { msg.push(errors); } var mb = null; mb = mbox({ title : "提示", message : msg.join("
"), buttons : { "关闭" : function() { mb.close(); } } }); } if (errorback) { errorback(result); } else if (callback) { callback(result); } } else { if (callback) { callback(result); } } }).error(function(a, b, c) { if (a.status == 500) { var mb = null; mb = mbox({ title : "系统提示", message : "系统发生内部错误,请稍后再试", buttons : { "关闭" : function() { mb.close(); } } }); return; } if (a.status == 403) { try { var m = a.responseText; m = eval("(" + m + ")"); mbox({ title : "系统提示", message : "您还没有登录,或者登录超时,请重新登录", buttons : { "跳转至登录页面" : function() { window.location.href = m["goto"]; } } }); } catch (e) { var mb = null; mb = mbox({ title : "系统提示", message : "您未授权访问此资源", buttons : { "关闭" : function() { mb.close(); } } }); } return; } var mb = null; mb = mbox({ title : "系统提示", message : "系统发生未知错误,请稍后再试", buttons : { "关闭" : function() { mb.close(); } } }); }); }; mbox = function(config) { config = config ? config : {}; var btitle = config.title ? config.title : ""; var message = config.message ? config.message : ""; var width = config.width ? config.width : 300; var height = config.height ? config.height : -1; var onclose = config.onClose ? config.onClose : function() { return true; }; var buttons = config.buttons ? config.buttons : null; var cover = $("
").css({ height : $(document.body).height() + "px" }).appendTo(document.body); var box = $("
"); box.cover = cover; box.css({ width : width + "px", left : (document.body.clientWidth - width) / 2 + "px", top : "-100000px" }); var top = $("
").appendTo(box); $("
" + btitle + "
").appendTo(top); $("
").click(function() { if (false === onclose()) { return; } box.remove(); cover.remove(); }).appendTo(top); var content = $("
"); if (typeof (message) == "string") { content.html(message); } else { content.append(message); } if (height != -1) { content.css("height", height + "px").css("overflow", config.overflow ? config.overflow : "auto"); } content.appendTo(box); var defaultButton = (typeof config.defaultButton == "undefined" ? true : false); if (!buttons && defaultButton) { buttons = { "关闭" : function() { if (false === onclose()) { return; } box.remove(); cover.remove(); } }; } box.appendTo(document.body); if (buttons) { var focusButton = config.focusButton; var bottom = $("
").appendTo(box); var bt = null; for ( var i in buttons) { bt = $("").click(function() { buttons[$(this).html()](); }).appendTo(bottom); if (i == focusButton) { var fbt = bt[0]; setTimeout(function() { fbt.focus(); }, 300); } } if (!focusButton && bt) { setTimeout(function() { bt[0].focus(); }, 300); } } box.close = function() { box.remove(); cover.remove(); $(document.body).unbind("keyup", box.onKeyEvent); }; var tp = ($(window).height() - $(box).height()) / 2 + "px"; if ($.browser.msie && $.browser.version == 6.0) { tp = ($(window).height() - $(box).height()) / 2 + $(window).scrollTop() + "px"; } else { box.css("position", "fixed"); } box.css("display", "none").css({ top : tp }).fadeIn(); box.onKeyEvent = function(e) { if (e.keyCode == 27) { e.stopPropagation(); if (false === onclose()) { return false; } box.close(); return false; } else if (e.keyCode == 37) { if (document.activeElement && document.activeElement.className == "mboxbtn") { var prev = $(document.activeElement).prev(); if (prev.length > 0 && prev[0].className == "mboxbtn") { prev[0].focus(); e.stopPropagation(); return false; } } } else if (e.keyCode == 39) { if (document.activeElement && document.activeElement.className == "mboxbtn") { var next = $(document.activeElement).next(); if (next.length > 0 && next[0].className == "mboxbtn") { next[0].focus(); e.stopPropagation(); return false; } } } }; $(document.body).bind("keyup", box.onKeyEvent); return box; }; var validator = function(name, config) { if (!window["_vldts"]) { window["_vldts"] = {}; } this.name = name; this.config = config ? config : (window[name] ? window[name] : {}); window["_vldts"][name] = this.config; var self = this; this.append = function(aconfig) { for ( var i in aconfig) { //对已有属性进行覆盖修改为进行扩展,li-shun,2013-06-15 //self.config[i] = aconfig[i]; if(typeof(self.config[i])=="object"){ $.extend(self.config[i],aconfig[i]); }else { self.config[i] = aconfig[i]; } } return self; }; this._cleanNode = function(node) { node.attr("title", ""); if (node.attr("_v_title")) { node.attr("title", node.attr("_v_title")); node.attr("_v_title", null); } if (!(node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox"))) { node.css("borderColor", ""); } if (node.attr("_v_border")) { if (!(node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox"))) { node.css("borderColor", node.attr("_v_border")); } node.attr("_v_border", null); } if (node.attr("_v_vname")) { node.attr("_v_vname", "_null"); } }; var fun = function(node, config, render) { if (!config) { return []; } if (typeof render == "undefined") { render = true; } var v = node.val(); var e = []; if (config.notNull) { if (v == null || v == "" || $.trim(v) == "") { e.push(config.notNull.msg ? config.notNull.msg : "此项不可为空"); } } if (v && config.length) { if (!(config.dataType && config.dataType.type && (config.dataType.type == "date" || config.dataType.type == "timestamp"))) { var p = true; var l = v ? slength(v) : 0; if (config.length.max) { if (l > config.length.max) { p = false; } } if (config.length.min) { if (l < config.length.min) { p = false; } } if (!p) { e.push(config.length.msg ? config.length.msg : "输入长度不符合要求"); } } } if (v && config.equalWith) { if (v != $("#" + config.equalWith["id"]).val()) { e.push(config.equalWith.msg ? config.equalWith.msg : "输入的值不符"); } } if (v && config.email) { var reg = config.email.regexp ? config.email.regexp : /^\w+((-\w+)|(\.\w+))*\@{1}\w+\.{1}\w{2,4}(\.{0,1}\w{2}){0,1}/ig; if (v.search(reg) == -1) { e.push(config.email.msg ? config.email.msg : "输入的邮箱格式不正确"); } } if (v && config.url) { var strRegex = "^((https|http|ftp|rtsp|mms)?://)?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" + "(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." + "[a-z]{2,6})(:[0-9]{1,4})?((/?)|(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; var reg = config.url.regexp ? config.url.regexp : new RegExp(strRegex); if (v.search(reg) == -1) { e.push(config.url.msg ? config.url.msg : "输入的网址格式不正确"); } } if (v && config.regexp) { if(typeof(config.regexp.regexp)=="string") config.regexp.regexp = eval("("+config.regexp.regexp+")"); if (v.search(config.regexp.regexp) == -1) { e.push(config.regexp.msg ? config.regexp.msg : "输入的格式不正确"); } } if (v && config.dataType) { if (config.dataType.type == "date" || config.dataType.type == "java.sql.Date" || config.dataType.type == "java.util.Date" || config.dataType.type == "timestamp" || config.dataType.type == "java.sql.Timestamp") { var reg = new RegExp( "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$"); var regt = new RegExp("^([0-1]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$"); var ts = v.split(" "); if (ts.length > 2) { e.push(config.dataType.msg ? config.dataType.msg : "输入的日期格式不正确"); } else { if (ts.length == 1) { if (ts[0].search(reg) == -1) { e.push(config.dataType.msg ? config.dataType.msg : "输入的日期格式不正确"); } } else { if (ts[0].search(reg) == -1 || ts[1].search(regt) == -1) { e.push(config.dataType.msg ? config.dataType.msg : "输入的日期格式不正确"); } } } } if (config.dataType.type == "big_decimal" || config.dataType.type == "java.math.BigDecimal") { var reg = new RegExp("^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$"); if (v.search(reg) == -1) { e.push(config.dataType.msg ? config.dataType.msg : "输入的数字格式不正确"); } } if (config.dataType.type == "long" || config.dataType.type == "java.lang.Long") { var reg = new RegExp("^[0-9]*$"); if (v.search(reg) == -1) { e.push(config.dataType.msg ? config.dataType.msg : "输入的数字格式不正确"); } } } if (v && config.precision && (typeof config.precision.max != "undefined")) { var pnum = v.split("."); //修正带有小数位是精度计算未考虑的bug。li-shun。2013-7-17 if(config.scale && (typeof config.scale.max != "undefined")){ if (pnum[0].length > (config.precision.max-config.scale.max)) { e.push(config.precision.msg ? config.precision.msg : "输入的数字整数部分不能超过" + config.precision.max + "位"); } }else { if (pnum[0].length > config.precision.max) { e.push(config.precision.msg ? config.precision.msg : "输入的数字整数部分不能超过" + config.precision.max + "位"); } } } if (v && config.scale && (typeof config.scale.max != "undefined")) { var pnum = v.split("."); if (pnum.length > 1 && pnum[1].length > config.scale.max) { e.push(config.scale.msg ? config.scale.msg : "输入的数字小数部分不能超过" + config.scale.max + "位"); } } if (config.custom) { config.custom(node, e); } if (render) { if (e.length > 0) { if (!(node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox"))) { node.css("borderColor", "red"); node.attr("title", e.join(",")); } } if (e.length == 0) { if (!(node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox"))) { node.attr("title", node.attr("_v_title") ? node.attr("_v_title") : ""); node.css("borderColor", node.attr("_v_border") ? node.attr("_v_border") : ""); } } } return e; }; this._bindNode = function(node) { node = $(node); if (node.attr("title")) { node.attr("_v_title", node.attr("title")); } if (node.css("borderColor")) { node.attr("_v_border", node.css("borderColor")); } if (!node.attr("_v_vname")) { if (node.attr("validUse")) { var vu = node.attr("validUse").split(","); for ( var i = 0; i < vu.length; i++) { if (!vu[i]) { continue; } node[vu[i]](function() { if ($(this).attr("_v_vname") && $(this).attr("_v_vname") != "_null") { fun($(this), window["_vldts"][$(this).attr("_v_vname")][$(this).attr("name")]); } }); } } else { node.blur(function() { if ($(this).attr("_v_vname") && $(this).attr("_v_vname") != "_null") { fun($(this), window["_vldts"][$(this).attr("_v_vname")][$(this).attr("name")]); } }); } } node.attr("_v_vname", self.name); }; this.bind = function(formid) { var form = $(formid); $("input,select,textarea", form).each(function(i, node) { node = $(node); self._cleanNode(node); if (node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox")) { return; } self._bindNode(node); }); return self; }; this.unbind = function(formid) { var form = $(formid); $("input,select,textarea", form).each(function(i, node) { node = $(node); self._cleanNode(node); }); return self; }; this.validate = function(formid, show) { var form = $(formid); var r = { hasError : false, errors : {} }; if (typeof show == "undefined") { show = true; } $("input,select,textarea", form).each(function(i, node) { node = $(node); if (node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox")) { var meta = window["_vldts"][self.name][node.attr("name")]; if (meta) { if (meta.notNull) { if ($("input[name='" + node.attr("name") + "']:checked", form).length == 0) { r.hasError = true; r["errors"][node.attr("name")] = [ meta.notNull.msg ? meta.notNull.msg : "请至少选择其中一项" ]; } } if (meta.length) { var l = $("input[name='" + node.attr("name") + "']:checked", form).length; if (meta.length.max && l > meta.length.max) { r.hasError = true; r["errors"][node.attr("name")] = [ meta.length.msg ? meta.length.msg : "此项选择数目过多" ]; } if (meta.length.min && l < meta.length.min) { r.hasError = true; r["errors"][node.attr("name")] = [ meta.length.msg ? meta.length.msg : "此项选择数目过少" ]; } } } } else { var render = false; if (node.attr("_v_vname") == self.name) { render = true; } var e = fun(node, window["_vldts"][self.name][node.attr("name")], render); if (e.length > 0) { r.hasError = true; r["errors"][node.attr("name")] = e; } } }); if (r.hasError && show) { var errors = r.errors; var msg = []; for ( var i in errors) { for ( var j = 0; j < errors[i].length; j++) { msg.push(errors[i][j]); } } var mb = null; mb = mbox({ title : "提示", message : msg.join("
"), buttons : { "关闭" : function() { mb.close(); } } }); } return r; }; }; function slength(inValue) { inValue = inValue.toString(); if (inValue == null || inValue == "") return 0; var len = 0; for ( var i = 0, l = inValue.length; i < l; i++) { if (inValue.charCodeAt(i) < 128) { len++; continue; } len += 2; } return len; } function showDialog(src, title, width, height, callback) { if ($("#frame1").length != 0) { $("#frame1")[0].parentNode.removeChild($("#frame1")[0]); } $("
") .appendTo(document.body); $("#frame1").attr("src", src); $("#frame1").dialog({ title : title, width : width, height : height, modal : true, draggable : false, resizable : false, parameter : "", close : function() { if (callback) { callback(); } } }); $("#frame1").dialog("option", "title", title); $("#frame1").dialog("option", "width", width + 20); $("#frame1").dialog("option", "height", height + 20); $("#frame1").dialog("open"); $("#frame1").css("width", width); $("#frame1").css("height", height); } String.prototype.getBytes = function() { var cArr = this.match(/[^\x00-\xff]/ig); return this.length + (cArr == null ? 0 : cArr.length); } function closeDialog(callback) { var $dialog = $("#frame1"); if(callback) { callback($dialog[0].contentWindow) } $dialog.dialog("close"); } $(function(){ $(".Wdate").click(function(){ if(!((typeof WdatePicker)==="undefined")){ WdatePicker(); } }) }) //获取QueryString的数组 function getQueryString() { var result = location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+", "g")); if (result == null) { return ""; } for ( var i = 0; i < result.length; i++) { result[i] = result[i].substring(1); } return result; } //根据QueryString参数名称获取值 function getQueryStringByName(name) { var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i")); if (result == null || result.length < 1) { return ""; } return result[1]; } //根据QueryString参数索引获取值 function getQueryStringByIndex(index) { if (index == null) { return ""; } var queryStringList = getQueryString(); if (index >= queryStringList.length) { return ""; } var result = queryStringList[index]; var startIndex = result.indexOf("=") + 1; result = result.substring(startIndex); return result; }