如何获取使用jquery中的索引1,2,3
的值?
<ul class="chosen-choices">
<li class="search-choice">
<span>American Black Bear</span>
<a class="search-choice-close" data-option-array-index="1"></a>
</li>
<li class="search-choice">
<span>Brown Bear</span>
<a class="search-choice-close" data-option-array-index="3"></a></li>
<li class="search-choice">
<span>Giant Panda</span>
<a class="search-choice-close" data-option-array-index="4"></a>
</li>
<li class="search-field">
<input type="text" value="Your Favorite Types of Bear" class="" autocomplete="off" style="width: 25px;" tabindex="16">
</li>
</ul>
答案 0 :(得分:4)
映射锚点,返回数据
var arr = $.map($('.search-choice a'), function(el) {
return $(el).data('option-array-index')
});