/* pageadmin基础函数方法 */ string.prototype.trim = function () //去除首尾空格 { return this.replace(/(^\s*)|(\s*$)/g, ""); } string.prototype.ltrim = function () //去除左空格 { return this.replace(/(^\s*)/g, ""); } string.prototype.rtrim = function () //去除右空格 { return this.replace(/(\s*$)/g, ""); } string.prototype.length = function () //获取字符长度,中文站两个字符 { return this.replace(/[^\x00-\xff]/g, "**").length; } string.prototype.left = function (len) //左边截取字段数 { var str = this; if (isnan(len) || len == null) { len = str.length; } else { if (parseint(len) < 0 || parseint(len) > str.length) { len = str.length; } } return str.substr(0, len); } string.prototype.right = function (len) //右边截取字段数 { var str = this; if (isnan(len) || len == null) { len = str.length; } else { if (parseint(len) < 0 || parseint(len) > str.length) { len = str.length; } } return str.substring(str.length - len, str.length); } //下面方法不同string.prototype,因为参数值可能是undefined function islstr(str) //是否由数字、字母和下划线组成 字母开头 { if (str == undefined) { return false; } if (str.trim() == "") { return false; } var reg = /^[a-za-z][a-za-z0-9_]*$/; if (reg.test(str)) return true; else return false; } function isstr(str) //是否由数字、字母和下划线组成 { if (str == undefined) { return false; } if (str.trim() == "") { return false; } return (str.replace(/\w/g, "").length == 0); } function isnumeric(str, symbol) //验证数值类型 { if (str == undefined) { return false; } if (str.trim() == "") { return false; } if (symbol == undefined) { symbol = ""; } switch (symbol) { case "+": //正数 return /(^\+?|^\d?)\d*\.?\d+$/.test(str); case "-": //负数 return /^-\d*\.?\d+$/.test(str); case "i": //整数 return /(^-?|^\+?|\d)\d+$/.test(str); case "+i": //正整数 return /(^\d+$)|(^\+?\d+$)/.test(str); case "-i": //负整数 return /^[-]\d+$/.test(str); case "f": //浮点数 return /(^-?|^\+?|^\d?)\d*\.\d+$/.test(str); case "+f": //正浮点数 return /(^\+?|^\d?)\d*\.\d+$/.test(str); case "-f": //负浮点数 return /^[-]\d*\.\d$/.test(str); default: //缺省,包括正负数,小数 if (isnan(str)) { return false; } else { return true; } } } function isint(str) //正整数 { if (str == undefined) { return false; } return /(^\d+$)|(^\+?\d+$)/.test(str); } function isusername(str) //是否是用户名由数字、字母和下划线汉字组成,不能为纯数字,不能包含@,便于后台的 { if (str == undefined) { return false; } if (str.trim() == "") { return false; } if (str.indexof("@") > 0) //包含邮箱规则返回false { return false; } if (isnumeric(str)) { //全是数字则返回false return false; } var reg = /^[\u4e00-\u9fff\w]{2,15}$/; return reg.test(str); } function ischinese(str) //是否为汉字 { if (str == undefined) { return false; } if (str.trim() == "") { return false; } return /^[^\x00-\xff]*$/.test(str); } function includechinese(str) //是否包含汉字 { if (str == undefined) { return false; } return (str.length != str.replace(/[^\x00-\xff]/g, "**").length); } function isdate(str) //是否是日期 { if (str == undefined) { return false; } if (str.trim() == "") { return false; } var reg1 = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/; var reg2 = /^(\d{4})-(\d{1,2})-(\d{1,2})$/; if (!reg1.test(str) && !reg2.test(str)) { return false; } return true; } function isdatetime(str) //是否是日期+时间格式 { if (str == undefined) { return false; } if (str.trim() == "") { return false; } var reg1 = /^(\d{1,2})\/(\d{1,2})\/(\d{4}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/; var reg2 = /^(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/; if (!reg1.test(str) && !reg2.test(str)) { return false; } return true; } function ismobile(mobile) //是否是手机号 { if (mobile == undefined) { return false; } var myreg = /^1[345678]\d{9}$/; if (!myreg.test(mobile)) { return false; } return true; } function isemail(str) //是否是邮箱号 { if (str == undefined) { return false; } var pattern = /^(?:[a-za-z0-9]+[_\-\+\.]?)*[a-za-z0-9]+@(?:([a-za-z0-9]+[_\-]?)*[a-za-z0-9]+\.)+([a-za-z]{2,})+$/; var flag = pattern.test(str.trim()); if (!flag) { return false; } else { return true; } } function isip(str) //是否是ip地址 { if (str == undefined) { return false; } var respacecheck = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/; if (respacecheck.test(str)) { str.match(respacecheck); if (regexp.$1 <= 255 && regexp.$1 >= 0 && regexp.$2 <= 255 && regexp.$2 >= 0 && regexp.$3 <= 255 && regexp.$3 >= 0 && regexp.$4 <= 255 && regexp.$4 >= 0) { return true; } else { return false; } } else { return false; } } function isimage(path) //是否是图片地址 { if (path == undefined) { return false; } var strfilter = ".jpeg|.gif|.jpg|.png|.bmp|" if (path.indexof(".") > -1) { var p = path.lastindexof("."); var strpostfix = path.substring(p, path.length) + '|'; strpostfix = strpostfix.tolowercase(); if (strfilter.indexof(strpostfix) > -1) { return true; } } return false; } //判断是否是手机浏览器 function ismobilebrowser() { var useragentinfo = navigator.useragent; var agents = ["android", "iphone", "symbianos", "windows phone", "ipad", "ipod"]; var flag = true; for (var v = 0; v < agents.length; v++) { if (useragentinfo.indexof(agents[v]) > 0) { flag = true; break; } } return false; } function unique(str) //字符串用半角逗号隔开,过滤重复和空字符 { if (str == undefined) { return ""; } var arr = str.split(","); var result = [], hash = {}; for (var i = 0, elem; (elem = arr[i]) != null; i++) { if (!hash[elem] && elem != "") { result.push(elem); hash[elem] = true; } } return result; } function urlencode(str) //对字符串进行encodeuricomponent编码,方便传入后台 { if (str == undefined) { return ""; } return encodeuricomponent(str); } function replaceall(str, str1, str2) //替换所有对应的字符串,默认的replace只替换第一个 { if (str == undefined) { return ""; } while (str.indexof(str1) >= 0) { str = str.replace(str1, str2); } return str; } function numericformat(str) //格式化字符串,只保留数字 { if (str == undefined) { return ""; } return str.replace(/\d/g, ""); } function strformat(str) //格式化字符串,只保留数字、字母部分 { if (str == undefined) { return ""; } return str.replace(/[\w]/g, ''); } function chineseformat(str) //格式化字符串,只保留汉字 { if (str == undefined) { return ""; } return (str.replace(/[^\u4e00-\u9fa5]/g, '')); } function inputnumeric() //只能输入数字,onkeyup调用 { this.value = numericformat(this.value); } function inputchinese() //只能输入中文,,onkeyup调用 { this.value = chineseformat(this.value); } function inputstr() //只能输入 字母,数字和 下划线,onkeyup调用 { this.value = strformat(this.value); } //数组中是否包含对应值 array.prototype.contains = function (value) { for (var i = 0; i < this.length; i++) { if (this[i] == value) { return true; } } return false }; //数组中删除对应的值 array.prototype.remove = function (value) { for (var i = 0; i < this.length; i++) { if (this[i] == value) { this.splice(i,1); } } return false }; //html5本地储存,localstorage保存的值都是string类型,expires过期秒数,设置了值则会通过添加cookie来控制过期时间。 function setlocalstorage(name, value, expires) { if (expires == undefined) { expires = 0;//默认不过期, } if (typeof (value) == "object") { value = json.stringify(value); } if (issupportlocalstorage()) { localstorage.setitem(name, value); if (expires > 0) { setcookie("_localstoragekey_" + name, "1", expires); } } else { setcookie(name, value, expires); } } //html5本地储存,hassetexpires表示是否设置了过期时间 function getlocalstorage(name, hassetexpires) { if (!hassetexpires) { hassetexpires = false; } if (issupportlocalstorage()) { if (hassetexpires) { var localstoragekey = getcookie("_localstoragekey_" + name); if (localstoragekey == "") { removelocalstorage(name); return ""; } } var strvalue = localstorage.getitem(name); if (strvalue == null) { strvalue = ""; } return strvalue; } else { return getcookie(name); } } //删除本地储存 function removelocalstorage(name) { if (issupportlocalstorage()) { localstorage.removeitem(name); delcookie("_localstoragekey_" + name); } else { delcookie(name); } } function issupportlocalstorage() { try { return 'localstorage' in window && window['localstorage'] !== null; } catch (e) { return false; } } function setcookie(name, value, expires, path)//cookies设置, { var argv = setcookie.arguments; var argc = setcookie.arguments.length; expires = (argc > 2) ? argv[2] : null;//第三个参数为过期时间 path = (argc > 3) ? argv[3] : null;//第4个参数为路径,不设置则默认为当前路径 if (expires != null) { if (typeof (expires) != "number") { expires = null; } var largeexpdate = new date(); //largeexpdate.settime(largeexpdate.gettime() + (expires*1000*60*60*24));//expires为过期天数 largeexpdate.settime(largeexpdate.gettime() + (expires * 1000)); //expires为过期秒数值 } if (path != null) { if (path.trim() == "") { path = null; } path = ";path=" + path; } document.cookie = name + "=" + decodeuricomponent(value) + ((expires == null) ? "" : (";expires=" + largeexpdate.togmtstring() + "")) + path; } function getcookie(name)//cookies读取 { var search = name + "=" if (document.cookie.length > 0) { offset = document.cookie.indexof(search) if (offset != -1) { offset += search.length end = document.cookie.indexof(";", offset) if (end == -1) end = document.cookie.length return unescape(document.cookie.substring(offset, end)) } else return "" } else { return ""; } } function delcookie(name)//删除cookie { var exp = new date(); exp.settime(exp.gettime() - 1); var cval = getcookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.togmtstring(); } //获取jqobj对象 function getjqueryobj(objname) { if (objname.indexof("#") == 0 || objname.indexof(".") == 0 || objname.indexof("=") > 0) { return $(objname); } else { return $("[name='" + objname + "']"); } } //给对象设置值,支持表单和html标签 ; (function ($) { $.fn.setvalue = function (thevalue) { var $thisobj = this; //var datasource = $thisobj.attr("data-source"); //if (datasource != undefined) { // thevalue = datasource; //} if (typeof (thevalue) == "undefined") { return; } if ($thisobj.length == 0) { console.error("setvalue对象不存在!"); return; } var tagname = $thisobj[0].tagname.tolowercase(); if ($thisobj.is('input')) { var attr = $thisobj.eq(0).attr("type"); if (attr == "checkbox" || attr == "radio") { $thisobj.setchecked(thevalue); } else { $thisobj.val(thevalue) } } else if ($thisobj.is('select')) { $thisobj.setselected(thevalue); } else if ($thisobj.is('textarea')) { $thisobj.val(thevalue) } else if ($thisobj.is('image')) { $thisobj.attr("src", thevalue); } else { $thisobj.html(thevalue) } return this; } })(jquery); //获取对象的值,包含表单,或html标签 ; (function ($) { $.fn.getvalue = function () { var rv = ""; var $thisobj = this; if ($thisobj.length == 0) { console.error("getvalue对象不存在!"); return; } var tagname = $thisobj[0].tagname.tolowercase(); if ($thisobj.is('input')) { var inputtype = $thisobj.eq(0).attr("type"); if (inputtype == undefined) { inputtype = "text"; } inputtype = inputtype.tolowercase(); if (inputtype == "checkbox" || inputtype == "radio") { rv = $thisobj.getchecked(); } else { rv = $thisobj.val(); } } else if ($thisobj.is('select')) { rv = $thisobj.getselected(); } else if ($thisobj.is('textarea')) { rv = $thisobj.val(); } else { rv = $thisobj.html(); } return rv; }; })(jquery); //检测radion或checkbox是否有选中的值 ; (function ($) { $.fn.ischecked = function () { var $thisobj = this; if ($thisobj.length == 0) { console.error("ischecked对象不存在!"); return; } var k = 0; for (k = 0; k < $thisobj.length; k++) { if ($thisobj.eq(k).is(":checked")) { return true; } } return false; }; })(jquery); ////反选checkbox ; (function ($) { $.fn.selectinvert = function () { var $thisobj = this; if ($thisobj.length == 0) { console.error("selectinvert对象不存在!"); return; } $thisobj.each(function () { var $this = $(this); if (typeof ($this.attr("disabled")) == "undefined") { if ($this.is(":checked")) { $this.prop("checked", false); } else { $this.prop("checked", true); } } }); }; })(jquery); //获取checkbox或radio选种的值,多个值用半角逗号隔开 ; (function ($) { $.fn.getchecked = function () { var $thisobj = this; if ($thisobj.length == 0) { console.error("getchecked对象不存在!"); return; } var selected = ""; $thisobj.each(function (index) { var $this = $(this); if ($this.attr("disabled")) { return true; } else if ($this.is(":checked")) { selected += "," + $this.val(); } }); return selected.replace(",", ""); }; })(jquery); ////根据值设置checkbox或radio表单 ; (function ($) { $.fn.setchecked = function (setvalue) { if (typeof (setvalue) == "undefined") { return; } var $thisobj = this; if ($thisobj.length == 0) { console.error("setchecked对象不存在!"); return; } setvalue = setvalue.tostring(); var arrsetvalue = setvalue.split(','); $thisobj.each(function () { var $this = $(this); if (arrsetvalue.contains($this.val()) || setvalue == "{*}") { $this.prop("checked", true); } else { $this.prop("checked", false) } }); return this; }; })(jquery); //获取select表单选中的值,多个值用半角逗号隔开。 ; (function ($) { $.fn.getselected = function () { var $thisobj = this; if ($thisobj.length == 0) { console.error("getselected对象不存在!"); return; } var $options = $thisobj.children("option:selected"); var selected = ""; $options.each(function (index) { var $this = $(this); if ($this.attr("disabled")) { return true; } else if ($this.is(":selected")) { selected += "," + $this.val(); } }); return selected.replace(",", ""); }; })(jquery); ////根据值设置select表单选中状态 ; (function ($) { $.fn.setselected = function (setvalue) { if (typeof (setvalue) == "undefined") { return; } var $thisobj = this; if ($thisobj.length == 0) { console.error("setselected对象不存在!"); return; } setvalue = setvalue.tostring(); if ($thisobj.attr("multiple")) //多选 { var $options = $thisobj.children("option"); var arrsetvalue = setvalue.split(','); $options.each(function () { var $this = $(this); if (arrsetvalue.contains($this.val()) || setvalue == "{*}") { $this.prop("selected", true); } else { $this.prop("selected", false) } }); } else //单选 { $thisobj.val(setvalue); if ($thisobj.get(0).selectedindex == -1) { $thisobj.get(0).selectedindex = 0; } return; } }; })(jquery); //清除select表单中选中的option ; (function ($) { $.fn.removeselected = function () { var $thisobj = this; if ($thisobj.length == 0) { console.error("removeselected对象不存在!"); return; } var $options = $thisobj.children("option:selected"); $options.remove(); }; })(jquery); //表单的序列化 (function ($) { //系列化一组json对象数组,itemobjname为每行数据的标识,可以为class,也可以为id $.fn.serializejsonlist = function (itemobjname) { var $thisobj = this; var $itemobj = $thisobj.find(itemobjname); if ($itemobj.length == 0) { return []; } var jsonarray = new array(); $itemobj.each(function (index) { //alert($(this).html()) jsonarray[index] = $(this).serializejson(); }); return jsonarray; }; //表单系列化成json对象 $.fn.serializejson = function () { var $thisobj = this; var serializeobj = {}; var array; if ($thisobj.is("form") || $thisobj.is("input") || $thisobj.is("textarea") || $thisobj.is("select")) { array = $thisobj.serializearray(); //serializearray()序列化成一个键值对数组,只对form表单有效 } else { array = $thisobj.find("input,select,textarea").serializearray(); //serializearray()序列化成一个键值对数组,只对form表单有效 } $(array).each(function () { if (serializeobj[this.name]) //如果存在相同key { serializeobj[this.name] = serializeobj[this.name] + "," + this.value;//同名name的值用半角逗号隔开 } else { serializeobj[this.name] = this.value; } }); return serializeobj; }; //序列化普通表单为url编码并用&连接的字符串格式 $.fn.serialize = function () { var $thisobj = this; if ($thisobj.is("form") || $thisobj.is("input") || $thisobj.is("textarea") || $thisobj.is("select")) { return $thisobj.serialize();//serialize() 只对form标签有效 } else { return $thisobj.find("input,select,textarea").serialize(); } }; //参数可以带多个逗号风格的obj对象参数 $.fn.serializes = function (additionals) { var elseparams = ""; if (typeof (additionals) != "undefined") { var arradditionals = additionals.split(","); for (var i = 0; i < arradditionals.length; i++) { var $obj = getjqueryobj(arradditionals[i]); if ($obj.length != 0) { elseparams += "&" + $obj.serialize(); } } } return this.serialize() + elseparams; } })(jquery); //组合对象,支持多个可变参数 function extendobject() { var newobject = {}; for (i = 0; i < arguments.length; i++) { newobject = $.extend(newobject, objectparse(arguments[i])); } return newobject; } //转对象,支持字符串和对象参数 function objectparse(obj) { var thetype = typeof (obj); if (thetype == "undefined") { obj = {}; } else if (thetype == "string") { try { var str = obj.trim(); if (str.indexof("{") == 0 || str.indexof("[") == 0) { obj = eval("(" + str + ")"); } else { obj = eval("(({" + str + "}))"); } } catch (err) { alert(obj + "的objectparse转换失败,请检测格式!"); throw new error("objectparse error!"); //alert("错误信息: " + err.message ); //obj = {}; } finally { } } else if (thetype == "object") { return obj; } else { obj = {}; } return obj; } function jsonparse(data) //转json,支持普通字符串,也支持js对象 { var thetype = typeof (data); if (data == undefined) { return undefined; } if (thetype == "object") { var str = json.stringify(data); //先转字符串 data = $.parsejson(str); //再转成对象 } else if (thetype == "string") { try { var str = data.trim(); if (str == "") { return undefined; } if (str == "{}") { return undefined; } if (str.indexof("{") == 0 || str.indexof("[") == 0) //json对象 { data = $.parsejson(str); } else { data = $.parsejson("{" + str + "}"); } } catch (err) { alert(data + "的jsonparse转换失败,请检测格式!"); //alert("错误信息: " + err.message ); data = undefined; } finally { } } return data; } //对象转字符串,普通js对象会转成json格式字符串 function jsontostring(obj) { if (typeof (obj) == "object") { obj = json.stringify(obj) } return obj; } function jsonformat(s) { var newstr = ""; for (var i = 0; i < s.length; i++) { c = s.charat(i); switch (c) { case '\"': newstr += "\\\""; break; case '\\': newstr += "\\\\"; break; case '/': newstr += "\\/"; break; case '\b': newstr += "\\b"; break; case '\f': newstr += "\\f"; break; case '\n': newstr += "\\n"; break; case '\r': newstr += "\\r"; break; case '\t': newstr += "\\t"; break; default: newstr += c; } } return newstr; } function multipleselecttoinput(jqobj, tojqobj) //把多选select的值转到input表单中 { if (jqobj.length == 0) { alert("对象不存在!"); return; } if (tojqobj.length == 0) { alert("目标对象不存在!"); return; } var vals = ""; var options = jqobj.children("option"); for (k = 0; k < options.length; k++) { var val = options.eq(k).val(); if (vals != "") { vals += ","; } if (val != "") { vals += val; } } tojqobj.val(vals); } //获取时间差,根据类型 function getdatediff(starttime, endtime, difftype) { starttime = starttime.replace(/-/g, "/"); //将xxxx-xx-xx的时间格式,转换为 xxxx/xx/xx的格式 endtime = endtime.replace(/-/g, "/"); difftype = difftype.tolowercase(); //将计算间隔类性字符转换为小写 var stime = new date(starttime); //开始时间 var etime = new date(endtime); //结束时间 var divnum = 1; //作为除数的数字 switch (difftype) { case "second": divnum = 1000; break; case "minute": divnum = 1000 * 60; break; case "hour": divnum = 1000 * 3600; break; case "day": divnum = 1000 * 3600 * 24; break; default: break; } return parseint((etime.gettime() - stime.gettime()) / parseint(divnum)); } //获取时间差,结果为,3天,5小时,40分钟,50秒 function gettimediff(st, et) { var rv; var st = new date(st.replace(/-/g, '/')); //开始时间转换为时间对象 var et = new date(et.replace(/-/g, '/')); //结束时间转换为时间对象 var dt = (et - st) / 1000; //得到时间差,转换为秒 var rd = math.floor(dt / (60 * 60 * 24)); //得到天数 var rh = math.floor((dt % (60 * 60 * 24)) / (60 * 60)); //得到小时 var rm = math.floor(((dt % (60 * 60 * 24)) % (60 * 60)) / 60); //得到分钟 var rs = (((dt % (60 * 60 * 24)) % (60 * 60)) % 60); //得到秒 rd = rd ? (rd + '天') : ''; rh = rh ? (rh + '小时') : ''; rm = rm ? (rm + '分钟') : ''; rs = rs ? (rs + '秒') : ''; rv = rd + rh + rm + rs; if (rv == "") { rv = "0秒"; } return rv; } function datetostr(datetime) { var year = datetime.getfullyear(); var month = datetime.getmonth() + 1;//js从0开始取 var date = datetime.getdate(); var hour = datetime.gethours(); var minutes = datetime.getminutes(); var second = datetime.getseconds(); if (month < 10) { month = "0" + month; } if (date < 10) { date = "0" + date; } if (hour < 10) { hour = "0" + hour; } if (minutes < 10) { minutes = "0" + minutes; } if (second < 10) { second = "0" + second; } var time = year + "-" + month + "-" + date + " " + hour + ":" + minutes + ":" + second; //2009-06-12 17:18:05 return time; } //数字转中文 function moneytochinese(money) { var cnnums = new array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"); //汉字的数字 var cnintradice = new array("", "拾", "佰", "仟"); //基本单位 var cnintunits = new array("", "万", "亿", "兆"); //对应整数部分扩展单位 var cndecunits = new array("角", "分", "毫", "厘"); //对应小数部分单位 var cninteger = "整"; //整数金额时后面跟的字符 var cnintlast = "元"; //整型完以后的单位 var maxnum = 999999999999999.9999; //最大处理的数字 var integernum; //金额整数部分 var decimalnum; //金额小数部分 var chinesestr = ""; //输出的中文金额字符串 var parts; //分离金额后用的数组,预定义 if (money == "") { return ""; } money = parsefloat(money); //alert(money); if (money >= maxnum) { $.alert('超出最大处理数字'); return ""; } if (money == 0) { chinesestr = cnnums[0] + cnintlast + cninteger; //document.getelementbyid("show").value=chinesestr; return chinesestr; } money = money.tostring(); //转换为字符串 if (money.indexof(".") == -1) { integernum = money; decimalnum = ''; } else { parts = money.split("."); integernum = parts[0]; decimalnum = parts[1].substr(0, 4); } if (parseint(integernum, 10) > 0) {//获取整型部分转换 zerocount = 0; intlen = integernum.length; for (i = 0; i < intlen; i++) { n = integernum.substr(i, 1); p = intlen - i - 1; q = p / 4; m = p % 4; if (n == "0") { zerocount++; } else { if (zerocount > 0) { chinesestr += cnnums[0]; } zerocount = 0; //归零 chinesestr += cnnums[parseint(n)] + cnintradice[m]; } if (m == 0 && zerocount < 4) { chinesestr += cnintunits[q]; } } chinesestr += cnintlast; //整型部分处理完毕 } if (decimalnum != '') {//小数部分 declen = decimalnum.length; for (i = 0; i < declen; i++) { n = decimalnum.substr(i, 1); if (n != '0') { chinesestr += cnnums[number(n)] + cndecunits[i]; } } } if (chinesestr == '') { chinesestr += cnnums[0] + cnintlast + cninteger; } else if (decimalnum == '') { chinesestr += cninteger; } return chinesestr; } /*获取url参数*/ function request(param, url) //获取url中参数 { if (param == undefined) { return ""; } if (url == null) { url = location.href; } var parastring = url.substring(url.indexof("?") + 1, url.length).split("&"); var paraobj = {} var returnvalue = ""; for (var i = 0; i < parastring.length; i++) { var item = parastring[i].split("="); if (item.length == 2 && param.tolowercase() == item[0].tolowercase()) { if (returnvalue != "") { returnvalue += ","; } returnvalue += item[1]; } } if (typeof (returnvalue) == "undefined") { return ""; } else { return decodeuri(returnvalue); } } function ajax(thisoptions, callback, errorcallback) { var rv = ""; //同步返回值,异步获取不到 if (callback == undefined) { callback = null; } if (errorcallback == undefined) { errorcallback = null; } var defaultoptions = { url: "", data: "", type: "get", async: true, cache: false, ifmodified: true, datatype: "json", timeout: 0,//单位为毫秒,0代表永远不超时 contenttype: "application/x-www-form-urlencoded;charset=utf-8", //可选:application/json beforesend: function (xhr) { //loading(); //console.log('beforesend') }, success: function (data, textstatus, jqxhr) { rv = data;//回调 if (callback != null) { if (typeof (callback) == "function") { callback.call(this, data, thisoptions);//方法回调 } } }, error: function (xhr, textstatus) { if (errorcallback != null) { if (typeof (errorcallback) == "function") { errorcallback.call(this, xhr, textstatus);//错误回调 } } //alert("ajax出现错误,status:" + xhr.status + ",textstatus:" + textstatus); }, complete: function (xhr, textstatus) { if (textstatus == "error") { //var newwin = open("/incs/_blank.html", "_blank"); //newwin.document.write(xhr.responsetext); console.log(xhr.responsetext); } } }; defaultoptions = extendobject({}, defaultoptions, thisoptions); if (defaultoptions.url.trim() == "") { alert("ajax的url参数不能为空"); return; } $.ajax(defaultoptions); return rv; } function callajax(type, async, url, dataparam, callback) { alert("callajax已经停用,请更换为ajax方法!"); }