var abspath = ''; /* 创建异步方法 */ function createxhr() { if (typeof xmlhttprequest != 'undefined') { return new xmlhttprequest(); } else if (typeof activexobject != 'undefined') { var version = [ 'msxml2.xmlhttp.6.0', 'msxml2.xmlhttp.3.0', 'msxml2.xmlhttp' ]; for (var i = 0; version.length; i ++) { try { return new activexobject(version[i]); } catch (e) { //跳过 } } } else { throw new error('您的系统或浏览器不支持xhr对象!'); } } //名值对转换为字符串 function paramsjoin(data) { var arr = []; for (var i in data) { arr.push(encodeuricomponent(i) + '=' + encodeuricomponent(data[i])); } return arr.join('&'); } //封装ajax function ajax(obj) { var xhr = createxhr(); obj.url = obj.url + '?rand=' + math.random(); obj.data = paramsjoin(obj.data); if (obj.method === 'get') obj.url += obj.url.indexof('?') == -1 ? '?' + obj.data : '&' + obj.data; if (obj.async === true) { xhr.onreadystatechange = function () { if (xhr.readystate == 4) { callback(); } }; } xhr.open(obj.method, obj.url, obj.async); if (obj.method === 'post') { xhr.setrequestheader('content-type', 'application/x-www-form-urlencoded'); xhr.send(obj.data); } else { xhr.send(null); } if (obj.async === false) { callback(); } function callback() { if (xhr.status == 200) { obj.success(xhr.responsetext); //回调传递参数 } else { alert('获取数据错误!错误代号:' + xhr.status + ',错误信息:' + xhr.statustext,'error');// 屏蔽错误信息 } } } /* js常用函数 v.0.0.1 */ function g(objname){if(document.getelementbyid(objname)){return eval('document.getelementbyid("'+objname+'")')}else{return eval('document.all.'+objname)}} //取得id的对象 function hide(a){ /* a = g(a); if(!a) return; a.style.display = "none"; a.style.visibility = 'hidden'; */ movechild(a); } function movechild(a){a=g(a);if(!a) return;document.body.removechild(a);} /* 获取物理高度 */ var getheight=function(){ var f=document,a=f.body,d=f.documentelement,c=f.compatmode=="backcompat"?a:f.documentelement; return math.max(d.scrollheight,a.scrollheight,c.clientheight) }; /* 获取物理宽度 */ var getwidth=function(){ var f=document,a=f.body,d=f.documentelement,c=f.compatmode=="backcompat"?a:f.documentelement; return math.max(d.scrollwidth,a.scrollwidth,c.clientwidth) }; //影藏遮罩层 function hide(){ hide('vmask'); movechild('vmask'); } /* 创建遮罩层 */ function cmask(){ thebody=document.body; v = document.createelement("div"); v.id = "vmask"; v.classname = "cscreen"; v.style.display = "block"; v.style.visibility = 'visible'; v.style.width = getwidth()+"px"; v.style.height = getheight()+"px"; thebody.appendchild(v); } /* 优化遮罩层 ps:随着屏幕的扩大或者缩小自动铺满 */ window.onresize = function(){ if(g("vmask")){ var obj = g("vmask"); obj.style.width = getwidth() + 'px'; obj.style.height = getheight() + 'px'; } } /* js判断元素是否在下标内 */ function in_array(key,array){ for(var i in array){ if(array[i]==key){ return true; } } return false; } /* 确定元素所在的下标 */ function sub_array(needle, haystack){ var result = []; for (i in haystack) { if (haystack[i] == needle){ result.push(i); } } return result; } /* 我的提示框 tipinfo:提示内容; tiptype:提示内容; time:显示时间; loading:是否是loading显示 0或者不填 为正常显示 cgs:是否创建虚拟层 0或者不填 不创建 */ function showtip(tipinfo,tiptype,time,cgs,loading){ /*屏幕的宽*/ var w=window.screen.availwidth; thebody=document.body; if($(".mytip_box").length==0){ d = document.createelement("div"); if(tiptype=='' || tiptype==undefined){ var tiptype = "提示";} if(time=='' || time==undefined){ var time = 2000;} if(cgs==1){cmask();} if(loading==undefined || loading==0){d.classname="mytip_box";content='

'+tiptype+'×

'+tipinfo+'

';}else{d.classname="mytip_box tiploading";content='

'+tiptype+'

'+tipinfo+'

';} d.innerhtml=content; thebody.appendchild(d); } $(".mytip_box").css("left",parseint((w-280)/2)); $(".mytip_box").show(); if(loading==undefined || loading==0){ settimeout(function(){ hidetip(); },time); } } /*隐藏 cgs:是否创建虚拟层 0或者不填 不创建 */ function hidetip(cgs){$(".mytip_box").hide().remove();if(cgs==undefined || cgs==0){}else{hide('cscreen')}} function checksearch(){ if($("#keyword").val()=="" || $("#keyword").val()=='请输入要搜索的关键词'){ showtip('请输入要搜索的关键词','系统提示',2000); return false; }else{ return true; } }