• jquery部分功能的实现


    第一个实现的功能 获取兄弟节点 

    window.jQuery = function(node){

    let node;

    return{
       geSiblings:function(){
     var allChildren = node.parentNode.children;
       var array = {
          length:0
         }
       for(let i =0;i<allChildren.length;i++){
       if(allChildren[i]!==node){
       array[array.length] = allChildren[i]
       array.length +=1;
         }
      }
    return array
     },

    }

    第二个 给节点添加类  和类型检查

    window.jQuery = function(nodeOrSelector){
    let node;
    if(typeof nodeOrSelector === 'string'){
    node = document.querySelectorAll(nodeOrSelector);
    }else{
    node = nodeOrSelector
    }
    return{
    geSiblings:function(){
    var allChildren = node.parentNode.children;
    var array = {
    length:0
    }
    for(let i =0;i<allChildren.length;i++){
    if(allChildren[i]!==node){
    array[array.length] = allChildren[i]
    array.length +=1;
    }
    }
    return array
    },
    addClass:function(classes){
    classes.forEach((value)=>node.classList.add(value))
    }
    }
    }

    最后一个功能 给元素修改文本内容

    window.jQuery = function(nodeOrSelector){
    let nodes;
    if(typeof nodeOrSelector === 'string'){
    nodes = document.querySelectorAll(nodeOrSelector)
    }else if(nodeOrSelector instanceof Node){
    nodes = {
    0:nodeOrSelector,
    length:1
    }
    }

    nodes.text = function(text){
    if(text === undefined){
    var texts = []
    for(let i =0;i<nodes.length;i++){
    nodes[i].textContent = text
    }
    return texts
    }else{
    for(let i =0;i<nodes.length;i++){
    nodes[i].textContent = text
    }
    }
    }
    return nodes;
    }

  • 相关阅读:
    BZOJ 4245: [ONTAK2015]OR-XOR
    BZOJ 2535: [Noi2010]Plane 航空管制2
    COGS 2551. 新型武器
    cogs2550. 冰桥,升起来了!
    大数模板
    uva 1513(线段树)
    uva 11525(线段树)
    poj 3368(RMQ模板)
    hdu 4686 Arc of Dream(矩阵快速幂)
    poj 3321 Apple Tree(树状数组)
  • 原文地址:https://www.cnblogs.com/Griffith/p/8879342.html
Copyright © 2020-2023  润新知