• 【js】简单模拟JQuery原理


           
     
           /*
                    模拟工厂函数
                */
                function L(selector){
                    var eles = document.querySelectorAll(selector);
                    var obj =new LQuery();
                    eles.forEach(function(item,index){
                        obj[index]=item;
                    })
                    obj.length=eles.length;
                    return obj;
                }
                /*
                    模拟Jquery函数对象
                */
                function LQuery(){
                   
                }
                LQuery.prototype={
            setHtml:function(val){
                        if(this.length>0){
                            for(var i=0;i<this.length;i++){
                                this[i].innerHTML=val;
                            }
                        }else{
                            throw new DOMException("null pointer exception")
                        }
                        return this;
                    }
                }
          //测试
          window.onload=function(){
             L("div").setHtml("<h1>test</h1>")
           } 
     
     
          //html部分
      
          <div></div>
              <div></div>
  • 相关阅读:
    HDU 2586 How far away?
    UVAlive 5796 Hedge Mazes
    HDU 4975 A simple Gaussian elimination problem.
    Poj 1149 PIGS
    HDU 3416 Marriage Match IV
    HDU 4912 Paths on the tree
    HDU 3277 Marriage Match III
    終於記起了帳號密碼
    codeforces194a
    codeforces195c
  • 原文地址:https://www.cnblogs.com/LightChan/p/8233254.html
Copyright © 2020-2023  润新知