//获取页面上的对象 function $getbyid(id) { var obj=document.getelementbyid(id); if(obj=="undifined") { obj=null; } return obj; } // end with string.prototype.endwith=function(str) { if(str==null||str==""||this.length==0||str.length>this.length) { return false; } if(this.substring(this.length-str.length)==str) { return true; } else { return false; } return true; } //start with string.prototype.startwith=function(str) { if(str==null||str==""||this.length==0||str.length>this.length) { return false; } if(this.substr(0,str.length)==str) { return true; } else { return false; } return true; } //去除字符串左右空格 string.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } //html符号转换 string.prototype.tostring = function() { return this.replace("<","<").replace(">",">"); } //判断字符串是否为空 string.prototype.isempty = function() { return this.trim().length ==0 ? true : false; } function isempty(id){ return $getbyid(id).value.isempty(); } //判断是否是电子邮箱 string.prototype.isemail = function() { try { var pattern=/^(([a-za-z\-_0-9]+[a-za-z\-_0-9\.]+)@[a-za-z\-_ 0-9]+\.([a-za-z]+(\.)?)?[a-za-z]+)$/; return pattern.test(this.trim()); } catch(e) { return false; } } function isemail(id){ return $getbyid(id).value.isemail(); } //判断字符串是否由字母数字组合 string.prototype.ischarandnum = function() { try { var pattern=/^([a-z a-z 0-9]+)$/; return pattern.test(this.trim()); } catch(e) { return false; } } //判断字符串的真实长度(中文和全角的字符算两个字节) string.prototype.reallength=function() { var str = this.trim().split(''); var length = 0; for(var i=0;imax) { return false; } return true; } //判断字符串是否含有中文或者全角的字符 string.prototype.isexistspecialchar = function() { return escape(this).indexof("%u") == "-1" ? false : true; } //判断字符串是否为英文、数字或符号‘-’ string.prototype.checkifenglish = function() { var string=this.trim(); var letters = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234567890-"; var i; var c; if(string.charat( 0 )=='-') { return false; } if( string.charat( string.length - 1 ) == '-' ) { return false; } for( i = 0; i < string.length; i ++ ) { c = string.charat( i ); if (letters.indexof( c ) < 0) { return false; } } return true; } //判断字符串长度是否匹配规定 string.prototype.checklengthmatch=function(min,max) { var str=this.trim(); var length=str.length; if(length@*\^?()+=\|{}\[\]\"\'\?/\\]+)$/; return !pattern.test(tx.trim()); } //判断域名是否正确 function checkdomainright(id) { var breturn = true; var obj=$getbyid(id); if(obj.value.reallength() >1024) { return false; } var list = obj.value.split('.'); if(list.length < 2) { return false; } for(var i=0;i64){ breturn = false; break; } } if(list[list.length-1].reallength()>4 || list[list.length-1].reallength()<2) { return false; } if(breturn == true) { var pattern=/^([^~!#$\s%@&*^?(){}_<>,:'¥+=\"\[\];|]*)$/; flag=pattern.test(obj.value.trim()); if(!flag) { breturn = false; } } return breturn; } //判断字符串是否为电话号码 string.prototype.checkphone=function() { try { var pattern = /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[0-9]{10}$)/; return pattern.test(this.trim()); } catch(e) { return false; } } function checkphone(id) { return $getbyid(id).value.checkphone(); } //判断字符串是否为邮政编码 string.prototype.checkcode=function() { try { var pattern = /^[1-9]{1}(\d){5}$/; return pattern.test(this.trim()); } catch(e) { return false; } } function checkcode(id) { return $getbyid(id).value.checkcode(); } //判断是否是ipv4 string.prototype.isipv4 = function() { try { var pattern=/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/; return pattern.test(this.trim()); } catch(e){ return false; } } function checkisipv4(id) { return $getbyid(id).value.isipv4(); } //设置操作结果提示 function setactionresult(id,bdislpay,success,msg) { var obj = $getbyid(id); obj.classname = success ? "succeed" : "erro"; obj.style.display = bdislpay ? "block" : "none"; if(msg != null) { obj.innerhtml = "

"+msg+"

"; } } //检查文件格式是否匹配 function checkimgtype(id) { var filename=$getbyid(id).value; var allimgext=$getbyid(id)["accept"]; var fileext=filename.substr(filename.lastindexof(".")+1).tolowercase(); if(allimgext.indexof(","+fileext+",")==-1) { return false; } return true; } //检测提示框 var chkpopflag; var iframechkpopflag; function checkchkpop(item,msg){ chkpopflag = false; item.focus(); var pos = getabsolutepos(item); var checkwin = document.createelement("div"); checkwin.id = "autopopchkwin"; if($getbyid(checkwin.id)!=null)document.body.removechild($getbyid(checkwin.id)); checkwin.style.position = "absolute"; checkwin.style.zindex = "10000"; content = "
" +"
" +"
" +"
" +msg +"
" +"
" +"
" +"
" checkwin.innerhtml = content; checkwin.style.left = pos.x + "px"; document.body.appendchild(checkwin); checkwin.style.top = pos.y - checkwin.offsetheight-2 + "px"; document.body.onclick = function(e){ e = e||window.event; var target = e.target || e.srcelement; var obj = $getbyid("autopopchkwin"); if(obj != null && chkpopflag && target != obj && target.parentnode!= "undefined" && target.parentnode!=null && target.parentnode != obj && target.parentnode.parentnode != obj){ document.body.removechild(obj); } chkpopflag = true; } item.onkeydown = document.body.onclick; } //提示文件上传错误的信息 function checkfileiframechkpop(item,f_x,f_y,msg){ iframechkpopflag = true; removefilesiframechkpop(); iframechkpopflag = false; var pos = getabsolutepos(item); var checkwin = document.createelement("div"); checkwin.id = "autopopchkwin"; if($getbyid(checkwin.id)!=null)document.body.removechild($getbyid(checkwin.id)); checkwin.style.position = "absolute"; checkwin.style.zindex = "1000"; content = "
" +"
" +"
" +"
" +msg +"
" +"
" +"
" +"
" checkwin.innerhtml = content; checkwin.style.left = pos.x + f_x + "px"; document.body.appendchild(checkwin); checkwin.style.top = pos.y - checkwin.offsetheight-2 + f_y + "px"; document.body.onclick = removefilesiframechkpop; item.onkeydown = removefilesiframechkpop; } function removefilesiframechkpop(){ try{ var obj = $getbyid("autopopchkwin"); if(obj != null && iframechkpopflag){ document.body.removechild(obj); } iframechkpopflag = true; }catch(oe){} } var intervalchkpop = null; var intervalchkpop_count = 0; function showchkpop(){ if(intervalchkpop_count==0) checkchkpop($getbyid("imgclose"),"点击或按esc键关闭窗口"); intervalchkpop_count ++; if(intervalchkpop == null){ intervalchkpop = setinterval("showchkpop()",100); } if(intervalchkpop_count==10){ window.clearinterval(intervalchkpop); intervalchkpop = null; intervalchkpop_count = 0; document.body.removechild($getbyid("autopopchkwin")); } } //获取标签对象位置 function getabsolutepos(el) { var sl = 0, st = 0; var rval; if(el) { var is_div = /^div$/i.test(el.tagname); if (is_div && el.scrollleft) sl = el.scrollleft; if (is_div && el.scrolltop) st = el.scrolltop; rval = { x: el.offsetleft - sl, y: el.offsettop - st ,w:0,h:0}; var tmp = this.getabsolutepos(el.offsetparent); rval.x += tmp.x; rval.y += tmp.y; } else { rval = {x:0,y:0,w:0,h:0}; } return rval; } //获取标签对象位置 function getabsolutepos2(el) { var sl = 0, st = 0; var rval; if(el) { var is_div = /^div$/i.test(el.tagname); if (is_div && el.scrollleft) sl = el.scrollleft; if (is_div && el.scrolltop) st = el.scrolltop; rval = { x: el.offsetleft - sl, y: el.offsettop - st }; if (el.offsetparent&&el.offsetparent.style.position=="relative") { var tmp = this.getabsolutepos(el.offsetparent); rval.x += tmp.x; rval.y += tmp.y; } } return rval; } //判断是否在容器中 function compareisincontainer(el,container) { if(el==container) return true; if (el.offsetparent) { if(getabsolutepos(el.offsetparent)) return true; } return false; } //判断浏览器 var explorer = function(){ this.name = navigator.appname; this.version = navigator.appversion; try{ if(this.name.trim() == "microsoft internet explorer"){ this.version = this.version.split('(')[1].split(';')[1].split(' ')[2]; this.name = "ie"; }else{ this.version = this.version.split('(')[0]; } }catch(e){ this.name = "ie"; this.version = "7.0"; } } //返回时间随机文件名 function getradomfilename(path){ var temp = path.split('.'); var exten = temp[temp.length-1]; var year,month,day,hours,minutes,seconds,ap; var intyear,intmonth,intday,inthours,intminutes,intseconds; var today; today=new date(); intyear=today.getyear(); intmonth=today.getmonth()+1; intday=today.getdate(); inthours=today.gethours(); intminutes=today.getminutes(); intseconds=today.getseconds(); return intyear+""+intmonth+""+intday+""+inthours+""+intminutes+""+intseconds+"."+exten; } //返回时间随机字符串 function getradomstring(){ var year,month,day,hours,minutes,seconds; var intyear,intmonth,intday,inthours,intminutes,intseconds; var today; today=new date(); intyear=today.getyear(); intmonth=today.getmonth()+1; intday=today.getdate(); inthours=today.gethours(); intminutes=today.getminutes(); intseconds=today.getseconds(); return intyear+""+intmonth+""+intday+""+inthours+""+intminutes+""+intseconds; } /*--------------------------------------------------- // 日期格式化 // 格式 yyyy/yyyy/yy/yy 表示年份 // mm/m 月份 // dd/dd/d/d 日期 // hh/hh/h/h 时间 // mm/m 分钟 // ss/ss/s/s 秒 ---------------------------------------------------*/ date.prototype.format = function(formatstr) { var str = formatstr; str=str.replace(/yyyy|yyyy/,this.getfullyear()); str=str.replace(/yy|yy/,(this.getyear() % 100)>9?(this.getyear() % 100).tostring():'0' + (this.getyear() % 100)); str=str.replace(/mm/,this.getmonth()>8?(this.getmonth()+1).tostring():'0' + (this.getmonth()+1)); str=str.replace(/m/g,this.getmonth()); str=str.replace(/dd|dd/,this.getdate()>9?this.getdate().tostring():'0' + this.getdate()); str=str.replace(/d|d/g,this.getdate()); str=str.replace(/hh|hh/,this.gethours()>9?this.gethours().tostring():'0' + this.gethours()); str=str.replace(/h|h/g,this.gethours()); str=str.replace(/mm/,this.getminutes()>9?this.getminutes().tostring():'0' + this.getminutes()); str=str.replace(/m/g,this.getminutes()); str=str.replace(/ss|ss/,this.getseconds()>9?this.getseconds().tostring():'0' + this.getseconds()); str=str.replace(/s|s/g,this.getseconds()); return str; } function addfiletype(filename,id) { var filetype=$getbyid(id).value; return filename+filetype.substr(filetype.lastindexof(".")).tolowercase(); } function getfilename(id) { var filename=$getbyid(id).value; return filename.substr(filename.lastindexof("\\")+1); } //-------重写event支持火狐------- function __firefox(){ htmlelement.prototype.__definegetter__("runtimestyle", __element_style); window.constructor.prototype.__definegetter__("event", __window_event); event.prototype.__definegetter__("srcelement", __event_srcelement); } function __element_style(){ return this.style; } function __window_event(){ return __window_event_constructor(); } function __event_srcelement(){ return this.target; } function __window_event_constructor(){ if(document.all){ return window.event; } var _caller = __window_event_constructor.caller; while(_caller!=null){ var _argument = _caller.arguments[0]; if(_argument){ var _temp = _argument.constructor; if(_temp.tostring().indexof("event")!=-1){ return _argument; } } _caller = _caller.caller; } return null; } if(window.attachevent) { } else if(window.addeventlistener){ __firefox(); } //-------重写event支持火狐------- document.onkeydown = function() { if(event.keycode == 27&&(parent.popwin.winlist.length>0&&parent.popwin.winlist[parent.popwin.winlist.length-1].id!="onlineeditobj"&&parent.popwin.winlist[parent.popwin.winlist.length-1].id!="systemloadingid")){ parent.popwin.close(); } } function checkall(form) { for (var i=0;i windoc.body.offsetheight) { xscroll = windoc.body.scrollwidth; yscroll = windoc.body.scrollheight; } else { xscroll = windoc.body.offsetwidth; yscroll = windoc.body.offsetheight; } var windowwidth, windowheight; if (self.innerheight) { windowwidth = self.innerwidth; windowheight = self.innerheight; } else if (windoc.documentelement && windoc.documentelement.clientheight) { windowwidth = windoc.documentelement.clientwidth; windowheight = windoc.documentelement.clientheight; } else if (windoc.body) { windowwidth = windoc.body.clientwidth; windowheight = windoc.body.clientheight; } //判断页面高度与窗口高度的比较 if(yscroll < windowheight) { pageheight = windowheight; } else { pageheight = yscroll; } if(xscroll < windowwidth) { pagewidth = windowwidth; } else { pagewidth = xscroll; } arraypagesize = new array(pagewidth,pageheight,windowwidth,windowheight); return arraypagesize; } function getdimensions() { var winwidth = 0; var winheight = 0; try { //获取窗口宽度 if (window.innerwidth) { winwidth = window.innerwidth; } else if ((document.body) && (document.body.clientwidth)) { winwidth = document.body.clientwidth; } //获取窗口高度 if (window.innerheight) { winheight = window.innerheight; } else if ((document.body) && (document.body.clientheight)) { winheight = document.body.clientheight; } //通过深入document内部对body进行检测,获取窗口大小 if (document.documentelement && document.documentelement.clientheight && document.documentelement.clientwidth) { winheight = document.documentelement.clientheight; winwidth = document.documentelement.clientwidth; } } catch (e){} return winwidth + ":" + winheight; } var intervalchkpop = null; var chkpops = new array(); var chkpopscount = 0; function listenchkpop(){ if($getbyid("framepage")==null)return; var divs = $getbyid("framepage").contentwindow.document.getelementsbytagname("div"); for(var i=0;i0){ chkpopscount = 0; intervalchkpop=setinterval("closechkpops()",100); } } function closechkpops(){ if(chkpopscount>50){ window.clearinterval(intervalchkpop); for(var i=0;i0) { type=(icon.classname=="openpage"?0:1); getitemid(type,id); } for(var i=0;i") return false; if(richvalue.reallength()max){ richvalue=(iframebody.innertext?iframebody.innertext:iframebody.textcontent); if(richvalue.reallength()>max) return false; } return true; } function createkeydown(btn){ document.onkeydown=function() { if(event.keycode==13) { $getbyid(btn).click(); return false; } } }