玩笑过后

导航

matchesSelector()方法

let result = element.matches(selectorString);
  • result 的值为 true 或 false.
  • selectorString 是个css选择器字符串.
  • if (!Element.prototype.matches) {
        Element.prototype.matches = 
            Element.prototype.matchesSelector || 
            Element.prototype.mozMatchesSelector ||
            Element.prototype.msMatchesSelector || 
            Element.prototype.oMatchesSelector || 
            Element.prototype.webkitMatchesSelector ||
            function(s) {
                var matches = (this.document || this.ownerDocument).querySelectorAll(s),
                    i = matches.length;
                while (--i >= 0 && matches.item(i) !== this) {}
                return i > -1;            
            };
    }

     

posted on 2018-08-23 18:03  玩笑过后  阅读(328)  评论(0编辑  收藏  举报