此页面 正在进行中

注意: WebPlatform 项目在 2012 年至 2015 年间由多个维护者支持,现已停止维护。该网站现在可在 github 上找到。

matches

摘要

如果元素匹配给定的选择器,则返回 true。否则,返回 false。

方法 of dom/HTMLElementdom/HTMLElement

语法

var result = element.matches(selector);

参数

selector

数据类型
字符串

此字符串表示要将元素测试的选择器。此参数是必需的,并且长度必须至少为一。空字符串会抛出错误 Dom Exception 12。

返回值

返回一个 DOM NodeDOM Node 类型的对象

如果元素匹配给定的选择器,则返回 true;否则返回 false。

用法

 Currently, few browsers support the unprefixed version. It is recommended to use the API as following:

var docEl = document.documentElement,
    matches = docEl.matches || docEl.webkitMatchesSelector || docEl.mozMatchesSelector || docEl.msMatchesSelector || docEl.oMatchesSelector;
matches.call(element, selector)

署名