情况是这样的:我有一个函数接受一个类的名称,就像在JQuery中一样:select(" .item");我使用的功能内部
document.getElementsByClassName()
但是,如果我使用select(" .item,.prize"),则它不起作用,因为您无法使用documents.getElementsByClassName()来选择多个类。有没有办法只使用JavaScript选择多个元素?
答案 0 :(得分:0)
我相信document.querySelectorAll
正是您所寻找的:
document.querySelectorAll(".item, .prize")
这应该返回一个包含类item
或prize
的所有元素的列表。