Element.prototype.matches不匹配裸对象:pseudoclass

问题描述 投票:0回答:1

由于某种原因,对于完全有效的CSS选择器(:hover),Element.prototype.matches返回false:

let n = /* an HTMLAnchorElement whose state is forced to :hover */;
console.log(n.matches(':hover')); // false
console.log(n.matches('a:hover')); // true
console.log(n.matches('*:hover')); // false
  • [找到一个DOM节点,并使用Elements面板将其状态强制为:hover,然后将n设置为$0后,我在开发工具控制台中运行了该代码。
  • [n可以是页面中的任何HTML dom节点-它不仅限于锚元素。]]
  • [此外,使用document.querySelector表现出相同的行为-但仅在我的本地测试环境上。例如,对于所有这些测试,https://google.com/返回true。

由于某种原因,对于完全有效的CSS选择器(:hover),Element.prototype.matches返回false:let n = / *一个HTMLAnchorElement,其状态被强制为:hover * /; console.log(n.matches(':hover'...

javascript google-chrome dom pseudo-class
1个回答
0
投票

是因为我在页面顶部缺少<!DOCTYPE html>。有关更多信息,请参见https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode

© www.soinside.com 2019 - 2024. All rights reserved.