繁体   English   中英

如何使用jquery获取li内部的值

[英]how to get the values inside the li using jquery

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

映射锚点,返回数据

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

小提琴

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM