Javascript 使用ChereIO的HTMLElement.querySelector()

Javascript 使用ChereIO的HTMLElement.querySelector(),javascript,cheerio,Javascript,Cheerio,使用香草JavaScript,您可以编写 const-box=document.querySelector(“.box”); const button=box.querySelector(“.button”); 干杯怎么样? 我想做一些类似的事情: constbox=$(“.box”); 常量按钮=方框。$(“.button”) 我这样问是因为我必须在元素上循环,然后在该元素中找到锚标记: const$=cheerio.load(stdout) 常量框=$(“.box”).map((i,元素

使用香草JavaScript,您可以编写

const-box=document.querySelector(“.box”);
const button=box.querySelector(“.button”);
干杯怎么样? 我想做一些类似的事情:

constbox=$(“.box”);
常量按钮=方框。$(“.button”)
我这样问是因为我必须在元素上循环,然后在该元素中找到锚标记:

const$=cheerio.load(stdout)
常量框=$(“.box”).map((i,元素)=>元素)
框。每个((i,元素)=>?可能是元素。查询选择器(“a”))

如果您不想使用后代组合器,可以使用:


我遇到一个错误,说“TypeError:element.find不是函数”我的代码:
框。每个((I,element)=>url.push(element.find(“a”).attr(“href”))
什么可能导致错误?请尝试使用$(element.find(“a”)
const button = box.find("button");