Skip to content
静心静心
HOME
DoubtfulCases
github icon
  • JAVASCRIPT

    • 封装Ajax
      • 面试题
        • 模块化JQuery
          • 深拷贝和浅拷贝
            • 有趣的javascript
              • 原型链
                • FAjax copy
                  • Javascrpt 中 方法
                    • JS获取数组的最后一项
                      • js正则正方向查找
                        • js重要
                          • 数字滚动
                            • 纯css手风琴
                              • JS设置全局变量
                                • JS 寄生式组合继承

                                author iconYYtimer icon小于 1 分钟

                                class Yy{
                                
                                    constructor(arg){
                                        if (typeof selector == "object") {
                                            this.el = [selector]
                                        } else {
                                            this.el = document.querySelectorAll(arg);
                                        }
                                    }
                                
                                    color(val) {
                                        console.log(this.el)
                                        for (let i = 0; i < this.el.length; i++) {
                                            console.log(this.el[i])
                                            this.el[i].style.color = val;
                                        }
                                        return this;
                                    }
                                
                                
                                    css = function (option, value) {
                                        if (value === undefined) {
                                            for (let i = 0; i < this.el.length; i++) {
                                                for (const key in option) {
                                                    this.el[i].style[key] = option[key];
                                                }
                                            }
                                        } else {
                                            for (let i = 0; i < this.el.length; i++) {
                                                this.el[i].style[option] = value;
                                            }
                                        }
                                        return this;
                                    }
                                
                                    addClass = function (...option) {
                                
                                        for (let i = 0; i < this.el.length; i++) {
                                            for (const value of option) {
                                                this.el[i].classList.add(value);
                                            }
                                        }
                                        return this;
                                    }
                                
                                
                                
                                    toggleClass = function (...option) {
                                        for (let i = 0; i < this.el.length; i++) {
                                            for (const value of option) {
                                                this.el[i].classList.toggle(value)
                                            }
                                        }
                                        return this;
                                    }
                                
                                    on = function (method, fn) {
                                        for (let i = 0; i < this.el.length; i++) {
                                            this.el[i].fn = fn;
                                            this.el[i].addEventListener(method, function (e) {
                                                this.fn(e);
                                            })
                                        }
                                    }
                                
                                
                                    attr = function (key, value) {
                                        for (let i = 0; i < this.el.length; i++) {
                                            if (value == undefined) {
                                                return this.el[i].getAttribute(key)
                                            }else{
                                                return this.el[i].setAttribute(key,value)
                                            }
                                        }
                                    }
                                  
                                }
                                
                                function instance(arg){
                                    return new Yy(arg)
                                }
                                let $ = instance;
                                export default $;
                                
                                1
                                2
                                3
                                4
                                5
                                6
                                7
                                8
                                9
                                10
                                11
                                12
                                13
                                14
                                15
                                16
                                17
                                18
                                19
                                20
                                21
                                22
                                23
                                24
                                25
                                26
                                27
                                28
                                29
                                30
                                31
                                32
                                33
                                34
                                35
                                36
                                37
                                38
                                39
                                40
                                41
                                42
                                43
                                44
                                45
                                46
                                47
                                48
                                49
                                50
                                51
                                52
                                53
                                54
                                55
                                56
                                57
                                58
                                59
                                60
                                61
                                62
                                63
                                64
                                65
                                66
                                67
                                68
                                69
                                70
                                71
                                72
                                73
                                74
                                75
                                76
                                77
                                78
                                79
                                80
                                81
                                82
                                83
                                edit icon编辑此页open in new window
                                上一页
                                面试题
                                下一页
                                深拷贝和浅拷贝
                                傻瓜都能写出计算机可以理解的代码。唯有能写出人类容易理解的代码的,才是优秀的程序员。
                                Copyright © 2022 YY

                                该应用可以安装在您的 PC 或移动设备上。这将使该 Web 应用程序外观和行为与其他应用程序相同。它将在出现在应用程序列表中,并可以固定到主屏幕,开始菜单或任务栏。此 Web 应用程序还将能够与其他应用程序和您的操作系统安全地进行交互。

                                详情