选择具有cheerio属性的元素 [英] Select elements with an attribute with cheerio
本文介绍了选择具有cheerio属性的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
选择具有特定属性的所有dom元素的最有效方法是什么.
What is the most efficient way to select all dom elements that have a certain attribute.
<input name="mode">
使用普通的javascript,我将使用:document.querySelectorAll("[name='mode']")
或document.querySelectorAll("[name]")
(如果我不在乎属性值).
With plain javascript I would use : document.querySelectorAll("[name='mode']")
or document.querySelectorAll("[name]")
if I don't care about the attribute value.
推荐答案
好吧,我在cheerio文档中找到了它,这是您的操作方法:
Ok I found it in the cheerio documentation, here is how you do it:
$('[name=mode]')
这篇关于选择具有cheerio属性的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文