// 通过id获取元素
        this.$ = function(id) {
            return document.getElementById(id);
        };

        // 通过标签名获取元素
        this.$$ = function(tagName, parent) {
            parent = parent || document;
            return parent.getElementsByTagName(tagName);
        };

        // 通过类名获取元素
        this.$Class = function(className, parent) {
            var arr = [], result = [];
            parent = parent || document;
            arr = this.$$("*");
            for (var i = 0, len = arr.length; i < len; i++) {
                if ((" " + arr[i].className + " ").indexOf(" " + className + " ") > 0) {
                    result.push(arr[i]);
                }
            }
            return result;
        };

相关文章:

  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2021-11-19
  • 2021-12-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案