部分JS

 //注册 studyez命名空间
 var  studyez=studyez ? studyez:{};
 //注册工具类命名空间
 studyez.tool=studyez.tool ? studyez.tool:{};
 //常用的工具类
 //注:本接口适合用提供工具类
 studyez.tool.helper=studyez.tool.helper ? studyez.tool.helper: {
      //注意:属性或是方法名之前不要加 this
      version: "1.0.0",
     
      $:function(id){
          return document.getElementById(id);
      },
     
      addEvent:function(id,eventName,funName){
          var o=$(id);
          if(o){
             o.attachEvent ? o.attachEvent("on"+eventName,funName):o.addEventListener(eventName,funName,false   );
          }
      },
     
      removeEvent:function(id,eventName,funName){
          var o=$(id);
          if(o){
              o.detachEvent ? o.detachEvent("on"+eventName,funName ): o.removeEventListener(eventName ,funName ,false );                  
          }
      },
      trimEnd:function(t){
         //除掉尾部空格
         return  t.replace(//s*$/g, "");   
      },
      trimStart:function(t){
         //除掉首部空格
         return  t.replace(/^/s*/g, "");   
         
      },
      trimEndStart:function(t){
          //除掉首尾空格
         return  t.replace(/(^/s*)|(/s*$)/g, "");   
      },
      trim:function(t){
         //除掉所有的空格
         return  t.replace(//s*/g, "");   
        // return t.replace(/(^ *)|( *$)/g, "");   
      },
      isInterger:function(t){
          //最多12位正整数
          return /^[1-9]/d{0,11}$/i.test(t);
      },
      isZero:function(t){
          //判断是否为零
          return /^0$/.test(t);
      },
      createXmlHttp:function(){
          //创建XmlHttpRequest组件
          //失败返回 null
          var http=false ;
          if(window.XMLHttpRequest){
                http = new XMLHttpRequest();
          }else if(window.ActiveXObject){
                var arrXmlHttpTypes = ['MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.3.0','Microsoft.XMLHTTP'];
                for(var i=0;i<arrXmlHttpTypes.length;i++){
                    try{
                        http = new ActiveXObject(arrXmlHttpTypes[i]);
                    }catch(ex){}//不支持MSXML.XMLHttp对象的IE
                }
          }
          if(http)
             return http;
          else
             return null;
      } ,
      setStyleClass:function(id,styleClass){
          //设置元素的 class属性值。
          var o=$(id);
          if(o){
            o.setAttribute(window.attachEvent ? "className":"class",styleClass);
          }
      }
 }
 //哈希表的实现
 studyez.tool.hashTable=function(){
    this._hash = new Object;
    this.add = function(key,value){
        if(typeof(key) == "undefined")
          return ;
        if(this.contains(key))
           return ;
        this._hash[key] = typeof(value) == "undefined" ? null:value;
    }
    this.remove = function(key){
          delete this._hash[key];
    }
    this.count = function(){
       var i=0;
       for(var k in this._hash){
            i++;
       }
       return i;
    }
    this.items = function(key){
       return this._hash[key];
    }
    this.contains = function(key){
       return typeof(this._hash[key]) != "undefined";
    }
    this.clear = function(){
       for(var k in this._hash){
          delete this._hash[k];
       }
    }
}
//通用树结点定义
studyez.tool.treeNode=function(key,text,parentId,pri){
     this.key=key ;
     this.text=text;
     this.parentId = parentId;
     this.pri=pri;
     this.parent=null;
     var  subs=new Array();
     var  dscCallback=function(node1,node2){
         return node1.pri -node2.pri;
     }
     var  ascCallback=function(node1,node2){
         return  node2.pri-node1.pri;
     }
     this.addSub=function(node){
         if(!(node  instanceof studyez.tool.treeNode))
             return ;
         if(node.parentId!=this.key)
             return ;
         node.parent=this;
         subs.push(node);
     }
     this.sort=function(desc){
         if(desc){
             subs.sort(dscCallback);
         } else {
             subs.sort(ascCallback);
         }
     }
     this.show=function(){
        var len=subs.length;
        var es="";
        for(var i=0;i<len ;i ++){
            es +=subs[i].key+",";
        }
        return es ;
     }
     this.subNode=function(){
       return subs;
     }
}
//括展原先的数据结构
studyez.tool.examTreeNode=function(key,text,parentId,pri,type){
     studyez.tool.treeNode.call(this,key,text,parentId,pri);
     this.type=type;
     this.getType=function(){
         return 10+this.type;
     }
}
function    createSubRadios(divId,cnt){
               var dv=document.getElementById(divId);
               for(var i=0;i<cnt ;i++){
               var  rdo;
                if(window.attachEvent){
                     rdo = document.createElement("<input type=/'radio/' name=/'rdo/' value=/'" + i + "/' id=/'rdo" + i + "/'>");
                 } else {
                    alert("here");
                     rdo=document.createElement("input");
                     rdo.setAttribute("name","xx");
                     rdo.type="radio";
                     rdo.value=i;
                 }
                 dv.appendChild(rdo);
                 dv.appendChild(document.createTextNode(i));
              }
        }
        function  createSubCheckboxs(divId,cnt){
             var dv=document.getElementById(divId);
               for(var i=0;i<cnt ;i++){
                    var  rdo;
                    rdo=document.createElement("input");
                    rdo.type="checkbox";
                    rdo.id=divId+"_sub_"+i;
                    rdo.value=i;
                    dv.appendChild(rdo);
                    dv.appendChild(document.createTextNode(i));
              }
        }

        function ShowMsg(strMsg){
          alert(strMsg);
        }
        function clear(){
            var ts=document.getElementById("st1");
            for(var i=0;i<ts.length;i ++){
                ts[i].checked=false;
            }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值