我想只遍歷包含特定元素作爲後代節點的父元素。通過包含特定後代節點的父元素遍歷
例如:
<div class="field">
<input type="text" />
</div>
<div class="field">
<input type="button" />
</div>
<div class="field">
<input type="text" />
</div>
我知道,使用XPath,它可以通過使用div[@class = 'field' and input[@type = 'text']]
使用jQuery完成的,我想用類似的東西div.field[input[type = 'text']]
。
我知道最近的選項是div.field > input[type = 'text']
,但這種方式我會迭代輸入而不是div。
在此先感謝
關於性能,'has'方法比'has'選擇更快。 – undefined
這就是我正在尋找的答案!謝謝 – w35l3y