zoukankan      html  css  js  c++  java
  • 【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-4123 Bob’s Race(树形dp+RMQ)
    hdu-4126 Genghis Khan the Conqueror(最小生成树+树形dp)
    hdu-4081 Qin Shi Huang's National Road System(最小生成树+bfs)
    hdu-1233 还是畅通工程(最小生成树)
    hdu-1102 Constructing Roads(最小生成树)
    codeforces 569D D. Symmetric and Transitive(bell数+dp)
    codeforces 569C C. Primes or Palindromes?(素数筛+dp)
    codeforces 569B B. Inventory(水题)
    修改ftp用户的目录
    安装ftp服务器
  • 原文地址:https://www.cnblogs.com/LightChan/p/8233254.html
Copyright © 2011-2022 走看看