我需要实现一个函数,该函数返回具有包含特定字符串的Id属性的第一个元素。
在HAP中,我曾经按以下方式实现它:
protected HtmlNode GetElementByIdPattern(string pattern)
{
return doc
.DocumentNode
.Descendants()
.FirstOrDefault(e => e.Attributes["id"] != null && e.Attributes["id"].Value.Contains(pattern));
}
如何遍历CsQuery中的所有元素?
解决方案是:
protected static CQ GetElementByIdPattern(CQ doc, string contains)
{
string select = string.Format("*[id*={0}]", contains);
return doc.Select(select).First();
}
基于jQuery语法:$(' [[id = contains]:first')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句