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;
    }

  • 相关阅读:
    简单工厂笔记
    P3369 【模板】普通平衡树 Treap树堆学习笔记
    tp5阿里云短信验证码
    centos 安装php
    tp6.0.2开启多应用模式
    linux navicat最新版过期
    git commit之后 取消commit
    服务器重置之后ssh root@报错
    git pull push 每次都需要输入账号和密码
    跨域问题 php
  • 原文地址:https://www.cnblogs.com/Griffith/p/8879342.html
Copyright © 2011-2022 走看看