• 精简版自定义 jquery


        function $(id) {
            var el = 'string' == typeof id ?
                document.getElementById(id) :
                id;
    
            el.on = function(event, fn) {
                if ('content loaded' == event) {
                    event = window.attachEvent ? "load" : "DOMContentLoaded";
                }
                el.addEventListener ?
                    el.addEventListener(event, fn, false) :
                    el.attachEvent("on" + event, fn);
            };
    
            el.all = function(selector) {
                return $(el.querySelectorAll(selector));
            };
    
            el.each = function(fn) {
                for (var i = 0, len = el.length; i < len; ++i) {
                    fn($(el[i]), i);
                }
            };
    
            el.getClasses = function() {
                return this.getAttribute('class').split(/s+/);
            };
    
            el.addClass = function(name) {
                var classes = this.getAttribute('class');
                el.setAttribute('class', classes ?
                    classes + ' ' + name :
                    name);
            };
    
            el.removeClass = function(name) {
                var classes = this.getClasses().filter(function(curr) {
                    return curr != name;
                });
                this.setAttribute('class', classes.join(' '));
            };
    
            return el;
        }
    
        function search() {
            var str = $('search').value.toLowerCase();
            var links = $('files').all('a');
    
            links.each(function(link) {
                var text = link.textContent.toLowerCase();
    
                if ('..' == text) return;
                if (str.length && ~text.indexOf(str)) {
                    link.addClass('highlight');
                } else {
                    link.removeClass('highlight');
                }
            });
        }
    
        $(window).on('content loaded', function() {
            $('search').on('keyup', search);
        });
  • 相关阅读:
    排序算法(二)插入排序---直接插入排序
    Shazam 是如何听音辨曲的?
    Android 读取<meta-data>元素的数据
    Android <uses-featureandroid:name="string">详解
    Android AsyncTask的用法
    Android ViewPager使用详解
    Git 使用教程(4)—— Git 常用命令集合
    Git 使用教程(3)
    Git 使用教程(2)
    Git 使用教程
  • 原文地址:https://www.cnblogs.com/webenh/p/7535322.html
Copyright © 2020-2023  润新知