zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    微信小程序解析xml
    微信小程序获取openid
    PHPExcel-1.8导出
    期末复习--实用回归分析
    一元线性回归
    链表
    WSL 配置oh-my-zsh
    Introduction to Computer Science and Programming in Python chap2
    树莓派的一些记录
    Top
  • 原文地址:https://www.cnblogs.com/Griffith/p/8879342.html
Copyright © 2011-2022 走看看