3.通過選擇器查找
1.queryElementSelector:通過選擇器查找,可以查找id名脐往、class名和標(biāo)簽名,但是只能找到一個(gè)
用法:
var ele = document.queryElementSelector("#main");
var ele = document.queryElementSelector(".main");
var ele = document.queryElementSelector("input");
- queryElementSelectorAll:這個(gè)也是通過選擇器查找再菊,可以查找id名摹闽、class名和標(biāo)簽名,可以查找所有并返回一個(gè)動(dòng)態(tài)集合 [數(shù)組]
用法:
var ele = document.queryElementSelectorAll("#main");
var ele = document.queryElementSelectorAll(".main");
var ele = document.queryElementSelectorAll("input");