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>
  • 相关阅读:
    题解 LNOI2014 LCA
    题解 P3413 【SAC#1
    题解 P3372 【【模板】线段树 1】(珂朵莉树解法)
    题解 P2610 【[ZJOI2012]旅游】
    题解 CF911D 【Inversion Counting】
    题解 CF1037D 【Valid BFS?】
    bootstrap常用部件下载
    sql获取上月同期
    VSS配置
    SQL中的union,except,intersect用法
  • 原文地址:https://www.cnblogs.com/LightChan/p/8233254.html
Copyright © 2011-2022 走看看