/* * author:wangxl * time:2007-09-14 * 对象类createSelectObject(下拉菜单对象) */ //创建下拉菜单对象 function createSelectObject(name){ this.name = name; this.xmlDoc; this.xmlObj; this.nodes; } //第一种方法定义 //加载xml createSelectObject.prototype.loadXML = function(url){ xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load(url); xmlObj=xmlDoc.documentElement; nodes = xmlDoc.documentElement.childNodes; } //得到结果集列表 createSelectObject.prototype.getNodesList = function(){ return nodes; } //删除所有下拉菜单中所有节点 createSelectObject.prototype.removeAll = function(){ obj = document.getElementById(this.name); for(var i=obj.options.length-1;i>=0;i--){ obj.remove(i); } //document.getElementById(this.name).innerHTML=""; } //添加所有选项//等于父编号的 createSelectObject.prototype.addItems = function(selectObj,items,nodeid,nodename,nodepid,nodepvalue){ if(nodepid==null||nodepid==""){ for (i=0;i=0; i--){ if (str.charCodeAt(i, 10)!=32 && str.charCodeAt(i, 10)!=160 && str.charCodeAt(i, 10)!=10 && str.charCodeAt(i, 10)!=13) break; } return str.substr(0, i+1); } /**(A22) * 方法:trimAll(); * 说明:删除字符串首尾部空格、回车、分隔字符; * 返回:Strig 字符串; * 参数:str String,需要处理的字符串; */ Operation.prototype.trimAll = function (str){ str=this.getValidStr(str); str=this.ltrimAll(str); str=this.rtrimAll(str); return str; } /**(A05) * 方法:getValidStr(); * 说明:确定获得的字符串为有效字符串; * 返回:Strig 字符串; * 参数:str String,需要处理的字符串; */ Operation.prototype.getValidStr = function (str){ str+=""; if (str=="undefined" || str=="null") return ""; else return str; } //-----------------------常用函数操作类end //------------------------创建排序对象 ------start /* * 常用三种类型转换(int float date string): * sValue 要转换的值 * sDataType 要转换的值的类型 */ function convert(sValue, sDataType) { sValue = new Operation().trimAll(sValue);//转型前取出前后空格 switch (sDataType) { case "int"://整型 return parseInt(sValue); case "float"://浮点型 return parseFloat(sValue); case "date"://日期型 return new Date(Date.parse(sValue)); default://任何其他类型返回字符串 return sValue.toString(); } } /* * 创建比较函数方法,这里采了闭包的方式,生成的比较函数根据所比较的列编号 * 与列数组类型不同而不同。 * iCol 要进行比较的列编号 * sDataType 列数据类型 */ function generateCompareTRs(iCol, sDataType) { /*真真的比较函数,供数组的sort方法调用,oTR1 oTR2两个参数由sort方法传进来 oTR1为比较的第一行,oTR2为比较的第二行*/ return function compareTRs(oTR1, oTR2) { var vValue1 = convert(" ",sDataType); var vValue2 = convert(" ",sDataType); //判断单元格是否有值,有值的情况下才赋值,否则为空 if(oTR1){ if(oTR1.cells[iCol]){ vValue1 = convert(oTR1.cells[iCol].innerText, sDataType); //vValue1 = convert(oTR1.cells[iCol].firstChild.nodeValue, sDataType); } } //判断单元格是否有值,有值的情况下才赋值,否则为空 if(oTR2){ if(oTR2.cells[iCol]){ vValue2 = convert(oTR2.cells[iCol].innerText, sDataType); //vValue2 = convert(oTR2.cells[iCol].firstChild.nodeValue, sDataType); } } //按升序比较,如果是日期类型时会自动调用其valueOf方法返date 的毫秒再进行比较 if (vValue1 < vValue2) { return -1; } else { if (vValue1 > vValue2) { return 1; } else { return 0; } } }; } /* * 表格比较,由HTML点击事件调用 * sTableID 要比较的表格id * iCol 要较的表格的列的编号 * sDataType 列的数据类型 */ function sortTable(sTableID, iCol, sDataType) { //获取表格对象 var oTable = document.getElementById(sTableID); //获取表格体 var oTBody = oTable.tBodies[0]; //获取表格体中所有行 var colDataRows = oTBody.rows; //存储所有表格行,借且于数组来进行排序处理 var aTRs = new Array; //把所有的行存储到数组里 for (var i = 0; i < colDataRows.length; i++) { aTRs[i] = colDataRows[i]; } /*sortCol为表格的扩展属性,标示最后是根据哪列来进行排序的。 如果要传进来的列与上次排序的列是同一列时,直接对数组进行 reverse反序操作,这样排序的速度会更快*/ if (oTable.sortCol == iCol) { aTRs.reverse(); } else { //如果是第一次排序,则调用排序算法进行排序 aTRs.sort(generateCompareTRs(iCol, sDataType)); } //创建文档碎片,这样不用一个一个把行添加到表格对象中,而是一次就可以了 var oFragment = document.createDocumentFragment(); for (var i = 0; i < aTRs.length; i++) { oFragment.appendChild(aTRs[i]); } //把所排序的行重样追加到表格对象中,注:这里没有单独先删除表格排序前的行 //因为如果追加的行是一样的话,appendChild操作会先自动删除后再添加。 oTBody.appendChild(oFragment); oTable.sortCol = iCol; } //------------------------创建排序对象 -----end /**//* ** ================================================================================================== ** 类名:CLASS_MSN_MESSAGE ** 功能:提供类似MSN消息框 ** 示例: --------------------------------------------------------------------------------------------------- var MSG = new CLASS_MSN_MESSAGE("gg",200,120,"短消息提示:","您有1封消息","今天请我吃饭哈"); MSG.show(); --------------------------------------------------------------------------------------------------- /**//* * 消息构造 */ function CLASS_MSN_MESSAGE(id,width,height,caption,title,message,url,target,action){ this.id = id; this.title = title; this.caption= caption; this.message= message; this.target = target; this.action = action; this.width = width?width:200; this.height = height?height:120; this.timeout= 150; this.speed = 20; this.step = 1; this.right = screen.width -1; this.bottom = screen.height; this.left = this.right - this.width; this.top = this.bottom - this.height; this.timer = 0; this.pause = false; this.close = false; this.autoHide = true; this.url = url; } /**//* * 隐藏消息方法 */ CLASS_MSN_MESSAGE.prototype.hide = function(){ if(this.onunload()){ var offset = this.height>this.bottom-this.top?this.height:this.bottom-this.top; var me = this; if(this.timer){ window.clearInterval(me.timer); } var fun = function(){ if(me.pause==false||me.close){ var x = me.left; var y = 0; var width = me.width; var height = 0; if(me.offset){ height = me.offset; } y = me.bottom - height; if(y>=me.bottom){ window.clearInterval(me.timer); me.Pop.hide(); } else { me.offset = me.offset - me.step; } me.Pop.show(x,y,width,height); } } this.timer = window.setInterval(fun,this.speed) } } /**//* * 消息卸载事件,可以重写 */ CLASS_MSN_MESSAGE.prototype.onunload = function() { return true; } /**//* * 消息命令事件,要实现自己的连接,请重写它 * */ CLASS_MSN_MESSAGE.prototype.oncommand = function(){ //this.close = true; this.hide(); window.parent.mainFrame.location = this.url; } /**//* * 消息显示方法 */ CLASS_MSN_MESSAGE.prototype.show = function(){ var oPopup = window.createPopup(); //IE5.5+ this.Pop = oPopup; var w = this.width; var h = this.height; var str = "
" str += "" str += "" str += "" str += "" str += "" str += "" str += "" str += "" str += "" str += "
" + this.caption + "" str += "×
" str += "
" + this.title + "

" str += "" str += "
" str += "
" str += "
" oPopup.document.body.innerHTML = str; this.offset = 0; var me = this; oPopup.document.body.onmouseover = function(){me.pause=true;} oPopup.document.body.onmouseout = function(){me.pause=false;} var fun = function(){ var x = me.left; var y = 0; var width = me.width; var height = me.height; if(me.offset>me.height){ height = me.height; } else { height = me.offset; } y = me.bottom - me.offset; if(y<=me.top){ me.timeout--; if(me.timeout==0){ window.clearInterval(me.timer); if(me.autoHide){ me.hide(); } } } else { me.offset = me.offset + me.step; } me.Pop.show(x,y,width,height); } this.timer = window.setInterval(fun,this.speed) var btClose = oPopup.document.getElementById("btSysClose"); btClose.onclick = function(){ me.close = true; me.hide(); } var btCommand = oPopup.document.getElementById("btCommand"); btCommand.onclick = function(){ me.oncommand(); } var ommand = oPopup.document.getElementById("ommand"); ommand.onclick = function(){ //this.close = true; me.hide(); window.open(ommand.href); } } /**//* ** 设置速度方法 **/ CLASS_MSN_MESSAGE.prototype.speed = function(s){ var t = 20; try { t = praseInt(s); } catch(e){} this.speed = t; } /**//* ** 设置步长方法 **/ CLASS_MSN_MESSAGE.prototype.step = function(s){ var t = 1; try { t = praseInt(s); } catch(e){} this.step = t; } CLASS_MSN_MESSAGE.prototype.rect = function(left,right,top,bottom){ try { this.left = left !=null?left:this.right-this.width; this.right = right !=null?right:this.left +this.width; this.bottom = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height; this.top = top !=null?top:this.bottom - this.height; } catch(e){} }