有人可以告诉我下面的代码有什么问题吗?它不会运行。 startNode.classList的返回值是什么?element.classList的输出是什么?
var startNode = document.body
if (startNode.classList.contains(className) {output.push(startNode)};
如果我这样做,它会运行。
if (startNode.classList.contains(className) {output.push(startNode)};
missing a closing parentheses here ---^
More about the API itself here:如果你不写语法错误
if (('' + startNode.classList + '').indexOf(className) > -1) {
output.push(startNode)
}
您的顶部代码缺少')'的if语句,你应该在你的控制台日志 –
看到一个语法错误,了解如何使用控制台来检查脚本错误... *给一个人一条鱼,或教他钓鱼* – charlietfl
['classList'](https://dom.spec.whatwg.org/#dom-element-classlist)返回['DOMTokenList'](https://dom.spec.whatwg.org /#domtokenlist)。 – Oriol