我有以下HTML:

<div class="questionItem">
<input data-val="true" data-val-number="The field MappingId must be a number."
data-val-required="The MappingId field is required."
id="answers_2__MappingId" name="answers[2].MappingId" type="hidden" value="23" />
<input id="answers_2__Item" name="answers[2].Item" type="hidden" value="B0300" />
<input id="answers_2__SetAnswer" name="answers[2].SetAnswer" type="hidden" value="^" />
</div>

jQuery will get me all the questionItems with this:

var coll = $('.questionItem');


我不需要所有这些,我只需要带有子输入的,名称为answers[/d+].SetAnswer和值?的questionItems。

如何构造该has()子句?

最佳答案

这里不需要正则表达式。只需使用:has和属性选择器:

$(".questionItem:has(input[name$='.SetAnswer'][value='?'])");


小提琴:http://jsfiddle.net/jonathansampson/S8kft/

07-28 10:29