var util = { alert: function (content, time, callback) { time = 3; if (typeof (time) == "undefined") { layer.open({ content: content, btn: '我知道了', end: function (index) { if (typeof (callback) === "function") { callback(index); } } }); } else { layer.open({ content: content , skin: 'msg' , time: time , end: function (index) { if (typeof (callback) === "function") { callback(index); } } }); } }, confirm: function (content, callback) { layer.open({ content: content, btn: ['确定', '取消'], yes: function (index) { if (typeof (callback) === "function") { callback(index); } } }); }, getIEVersion: function () { if (window.ActiveXObject) { var v = navigator.userAgent.match(/MSIE ([^;]+)/)[1]; return parseFloat(v.substring(0, v.indexOf("."))); } return false; }, isIE6: function () { if (window.ActiveXObject) { var v = navigator.userAgent.match(/MSIE ([^;]+)/)[1]; if (v === '6.0') return true; } return false; }, isEmail: function (str) { var re = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; if (re.test(str) != true) { return false; } else { return true; } }, /** * 判断是否身份证号码 */ isIdCard: function (str) { var re = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; if (re.test(str) != true) { return false; } else { return true; } }, /** * 判断是否手机号码 */ isMobile: function (str) { var re = /(^1[3,4,5,6,7,8,9]\d{9}$)/; if (re.test(str) != true) { return false; } else { return true; } }, /** * 判断是否为小数 */ isValidDecimal: function (chars) { var re = /^\d*\.?\d{1,2}$/; if (chars.match(re) == null) return false; else return true; }, isValidPwd: function (str) { var re = /^[\x21-\x7E]{6,16}$/; if (re.test(str) != true) { return false; } else { return true; } }, /** * 判断是否为整数 */ isInt: function (chars) { var re = /^\d*$/; if (chars.match(re) == null) return false; else return true; }, /** * 判断是否为英文字母 */ isLetters: function (str) { var re = /^[A-Za-z]+$/; if (str.match(re) == null) return false; else return true; }, /** * 判断是否为邮政编码 */ isValidPost: function (chars) { var re = /^\d{6}$/; if (chars.match(re) == null) return false; else return true; }, isValidInput: function (str) { var re = /[(\ )(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/; if (re.test(str) != true) { return false; } else { return true; } }, /** * 将浮点数四舍五入,取小数点后2位,如果不足2位则补0,这个函数返回的是字符串的格式 */ sishewuru: function (x) { var f_x = parseFloat(x); if (isNaN(f_x)) { return ''; } var f_x = Math.round(x * 100) / 100; var s_x = f_x.toString(); var pos_decimal = s_x.indexOf('.'); if (pos_decimal < 0) { pos_decimal = s_x.length; s_x += '.'; } while (s_x.length <= pos_decimal + 2) { s_x += '0'; } return s_x; }, submit: function (url, dataArr) { $.ajax({ url: url, data: dataArr, type: 'post', datatype: 'json', success: function (Data) { if (Data.Result != null && Data.Result == true) { location.reload(); } else { alert(Data.Msg); } } }); }, callbackSubmit: function (url, dataArr, callback, ifAsync) { if (typeof (ifAsync) === "undefined") ifAsync = true; var index=-1; if (!ifAsync) index=layer.open({ type: 2, content: '
加载中,请稍等
', shadeClose: false }); $.ajax({ url: url, data: dataArr, type: 'post', async: ifAsync, datatype: 'json', success: function (Data) { if (Data.Result === false && typeof (Data.Redirect) !== "undefined") { if (typeof Data.Msg !== "undefined") util.alert(Data.Msg, 2, function () { location.replace(Data.Redirect); }); else location.replace(Data.Redirect); return false; } callback(Data); }, error: function (e) { util.alert("请求出错") }, complete: function () { if (index > -1) layer.close(index); } }); }, is_weixn: function () { var ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == "micromessenger") { return true; } else { return false; } }, IsAndroid:function() { var u = navigator.userAgent; return u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; }, IsIos:function() { var u = navigator.userAgent; return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); } };