当使用 .map() 方法时,我得到了一个我认为有两个节点的数组(不是 jQuery 对象/匹配集)。我想申请这组课程,但没有任何反应。
$('input#substance, input[name="atc_code"]').map(function() {return $(this).prevAll('label:first')});
回报:
[x.fn.x.init[1], x.fn.x.init[1]]
[
x.fn.x.init[1]
0: label
context: input#substance.ui-autocomplete-input
length: 1
prevObject: x.fn.x.init[1]
__proto__: Object[0]
,
x.fn.x.init[1]
0: label
context: input.small ui-autocomplete-input
length: 1
prevObject: x.fn.x.init[1]
__proto__: Object[0]
它选择正确但为什么我不能使用这个数组?为什么它不是 jQuery 对象?
的HTML:
<div class="fieldset-container">
<label>Substance</label>
<span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>
<input type="text" name="substance" id="substance" maxlength="22" autocomplete="off" spellcheck="false" autofocus="autofocus" class="ui-autocomplete-input">
<label title="Required field">ATC code<span class="ma">*</span></label>
<span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span><input type="text" class="small ui-autocomplete-input" name="atc_code" maxlength="7" autocomplete="off" spellcheck="false">
<label>Year</label>
<div class="small">
<select name="year">...</select>
</div>
</div>