如何使用jquery获取li中的值

时间:2015-02-09 18:18:39

标签: javascript jquery html

如何获取使用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>

1 个答案:

答案 0 :(得分:4)

映射锚点,返回数据

var arr = $.map($('.search-choice a'), function(el) { 
    return $(el).data('option-array-index') 
});

FIDDLE