zoukankan      html  css  js  c++  java
  • no-jquery 01Elements

    Select Elements

    id

    // IE 5.5+
    document.getElementById('myElement');
    
    // IE 8+
    document.querySelector('#myElement');
    

    class

    // IE 9+
    document.getElementsByClassName('myElement');
    
    // IE 8+
    document.querySelectorAll('.myElement');
    

    Pseudo-class

    // IE 8+
    document.querySelectorAll('#myForm :invalid');
    

    tagName

    // IE 5.5+
    document.getElementsByTagName('div');
    
    // IE 8+
    document.querySelectorAll('div');
    

    attribute

    // IE 8+
    document.querySelectorAll('[data-foo-bar="someval"]');
    

    Children

    // IE 5.5+
    // NOTE: This will include comment and text nodes as well.
    document.getElementById('myParent').childNodes;
    
    // IE 9+ (ignores comment & text nodes).
    document.getElementById('myParent').children;
    
    // IE 8+
    document.querySelector('#myParent > [ng-click]');
    

    Descendants

    // IE 8+
    document.querySelectorAll('#myParent A');
    

    Excluding Elements

    // IE 9+
    document.querySelectorAll('DIV:not(.ignore)');
    

    Multiple Selectors

    // IE 8+
    document.querySelectorAll('DIV, A, SCRIPT');
    

    Pattern

    window.$ = function(selector) {
        var selectorType = 'querySelectorAll';
    
        if (selector.indexOf('#') === 0) {
            selectorType = 'getElementById';
            selector = selector.substr(1, selector.length);
        }
    
        return document[selectorType](selector);
    };
    
  • 相关阅读:
    概率图模型课堂笔记:2.4 取样方法
    概率图模型课堂笔记:2.2 置信度传播
    2018秋季学期学习总结
    人生路上影响最大的三位老师
    抓老鼠啊~亏了还是赚了?
    币值转换
    自我介绍
    打印沙漏
    2019春第七周作业
    第六周编程总结
  • 原文地址:https://www.cnblogs.com/jinkspeng/p/4478183.html
Copyright © 2011-2022 走看看