document.querySelectorAll JavaScript · 网页功能
用 CSS 选择器获取文档中所有匹配的元素集合。
怎么用
document.querySelectorAll("选择器")
小例子
var items = document.querySelectorAll(".item");
console.log(items.length);
运行结果
匹配元素的数量
提醒:返回静态的 NodeList,可用 forEach 或 for...of 遍历。
官方文档:https://developer.mozilla.org/zh-CN/docs/Web/API/Document/querySelectorAll
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← JavaScript全部词条