/** * 获得浏览器类型 */ function Browser() { var ua, s, i; this.isIE = false; // Internet Explorer this.isOP = false; // Opera this.isNS = false; // Netscape this.version = null; ua = navigator.userAgent; s = "Opera"; if ((i = ua.indexOf(s)) >= 0) { this.isOP = true; this.version = parseFloat(ua.substr(i + s.length)); return; } s = "Netscape6/"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = parseFloat(ua.substr(i + s.length)); return; } s = "Gecko"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = 6.1; return; } s = "MSIE"; if ((i = ua.indexOf(s))) { this.isIE = true; this.version = parseFloat(ua.substr(i + s.length)); return; } } var browser = new Browser(); function getElements(name){ if(browser.isIE){ return document.all(name); }else{ return document.getElementsByName(name); } } /*使firefox里能使用outerHTML*/ var setOuterHtml = function(s){ var range = this.ownerDocument.createRange(); range.setStartBefore(this); var fragment = range.createContextualFragment(s); //alert(fragment.xml); this.parentNode.replaceChild(fragment, this); }; if(window.HTMLElement) { HTMLElement.prototype.__defineSetter__("outerHTML", setOuterHtml); } /** * 表单提交 */ function formSubmit(forumId,button){ if (button){ button.disabled="true"; } document.getElementById(forumId).submit(); } /** * 表单提交 */ function submit(forumId){ document.getElementById(forumId).submit(); } /** * 表单清除 */ function formReset(forumId){ document.getElementById(forumId).reset(); } /** * 获得事件操作对象 */ function getEventSrcElement(event){ var obj; if (browser.isIE) obj = window.event.srcElement; else obj = event.currentTarget; return obj; } /** * 获得鼠标移向目标 */ function getEventToElement(event){ var el; if (browser.isIE) el = window.event.toElement; else if (event.relatedTarget != null) el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode); return el; } /** * 获得指定对象相对于浏览器的绝对定位 */ function getAbsolutePosition(obj){ var top = obj.offsetTop; var left = obj.offsetLeft; var width=obj.offsetWidth; var height=obj.offsetHeight; while(obj.offsetParent){ obj = obj.offsetParent; top += obj.offsetTop; left += obj.offsetLeft; } return {"top":top, "left":left, "width":width, "height":height}; } /** * 获得指定对象相对于最近一个relative 或者 absolute 对象的相对位置 */ function getRelativePosition(obj) { var top=obj.offsetTop; var left=obj.offsetLeft; var width=obj.offsetWidth; var height=obj.offsetHeight; obj = obj.offsetParent while (obj) { var positionValue = Element.getStyle(obj, "position"); var overflowValue = Element.getStyle(obj, "overflow"); if ( positionValue == 'absolute' || positionValue == 'relative' || ( overflowValue != 'visible' && overflowValue != '' ) ){ break; } top += obj.offsetTop; left += obj.offsetLeft; obj = obj.offsetParent; } return {"top":top, "left":left, "width":width, "height": height}; } /** * 获得对象本身及外部 第一个tagName和className为指定值的对象 */ function getContainerWith(node, tagName, className) { while (node != null) { if (node.tagName != null && node.tagName == tagName && Element.hasClassName(node, className)) return node; node = node.parentNode; } return node; } /** * 获得指定对象的子对象的offsetWidth */ function getChildNodeWidth(el){ var maxWidth = 0; if(el.childNodes){ for(i=0;i maxWidth){ maxWidth = w; } } } if(maxWidth!=0) return maxWidth; } return Element.getWidth(el); } /** * 获取浏览器的有些屏幕相对坐标及大小 */ function getBrowserOffset(){ var top = 0; var left = 0; var width = 0; var height = 0; if (document.documentElement) { top = document.documentElement.scrollTop; left = document.documentElement.scrollLeft; width = document.documentElement.clientWidth; height = document.documentElement.clientHeight; } else if (document.body) { top = document.body.scrollTop; left = document.body.scrollLeft; width = document.body.clientWidth; height = document.body.clientHeight; } return {"top": top, "left": left, "width": width, "height": height}; } /** * 去字符串两端的空格 */ function LTrim(s){ for(var i=0;i=0;i--) if(s.charAt(i)!=' ') return s.substring(0,i+1); return ""; } //获取字符串的长度 function getLength(moji) { var i,cnt = 0; for(i=0; i= 4 ) cnt+=2; else cnt++; return cnt; } function Trim(s){ return RTrim(LTrim(s)); } /*=================== 设置png图片在ie浏览器下背景透明,firefox不需要 ==============================*/ function correctPNG() { for(var i=0; i" img.outerHTML = strNewHTML i = i-1 } } } function checkFileSize(fileName,maxsize){ alert('cao') var filesize =getFileSize(fileName); alert(filesize+":"+maxsize) if(filesize==true ||filesize==false || filesize==-1 ){ return true; }else{ if(filesize>maxsize){ return false; } } } function getFileSize (fileName) { if(document.layers){ if(navigator.javaEnabled()){ var file = new java.io.File(fileName); if(location.protocol.toLowerCase()!='file:') netscape.security.PrivilegeManager.enablePrivilege( 'UniversalFileRead'); return file.length(); } else return -1; } else if(document.all){ window.oldOnError= window.onerror; window.onerror=function(err){ if(err.indexOf('utomation')!=-1){ alert('系统禁止js检查文件大小,将进行后台验证'); return true; } else return false; }; var fso=new ActiveXObject('Scripting.FileSystemObject'); var file=fso.GetFile(fileName); window.onerror = window.oldOnError; return file.Size; } else{ return true; } } function saveSuccess(message){ if (message==null) { message="保存成功"; } alert(message); } /** * 交替替换一个元素的className * @param obj 替换元素 * @param name1 className1 * @param name2 className2 */ function changeClass(obj,name1,name2){ if(obj.className==name1){ obj.className=name2; }else if(obj.className==name2){ obj.className=name1; } } /** * 交替替换一个元素属性的值 * @param obj 替换元素的属性 * @param name1 值1 * @param name2 值2 * @param property 值 */ function changeProperty(obj,name1,name2,property){ if(eval("obj.style."+property)==name1){ eval("obj.style."+property+"=name2") }else if(eval("obj.style."+property)==name2){ eval("obj.style."+property+"=name1"); } } function changeDisplay(obj){ changeProperty(obj,'none','block',"display"); } function selectAll(str){ var checkbox=document.getElementsByName(str); if(checkbox){ if(checkbox.length){ for(var i=0;i"; s = s + ""; s = s + ""; s = s + ""; s = s + "
"+title+"
"; s = s + ""; s = s + "
"; s = s + "
"+msgtitle+"
"; s = s + "
"+msgcontent+"
"; s = s + "
"; s = s + "
"; s = s + " "+linktitle+""; s = s + "
"; bodydiv.innerHTML = s; ebalerts.push(this); document.body.appendChild(bodydiv); } this.close = function(){ bodydiv.style.visibility = "hidden"; ebalerts.splice(index,1); document.body.removeChild(bodydiv); index = -1; } this.move = function(x,y){ bodydiv.style.display='block'; bodydiv.style.left= x + "px"; bodydiv.style.top= y + "px"; } this.init(); } function alertsMove(){ if(ebalerts.length>0){ var screenX=bdy.scrollLeft; var screenY=bdy.scrollTop; var screenW=bdy.clientWidth-ebalertwidth - 10 ;//22:border width var screenH=bdy.clientHeight-ebalertheight -10;//10:border height for(var i=0;iindex){ ebalerts[index].close(); } } /*=================== alert窗口end =============================================*/