jQuery在ul li中查找元素 [英] jQuery find element in ul li span

查看:190
本文介绍了jQuery在ul li中查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML结构为:

<div title="" class="interestareascategories_chn chzn-container chzn-container-multi">
    <ul id="ul_deptType" class="chzn-choices">
        <li id="li_dept_1" ver="old" class="search-choice"> <span>DEV</span>    <a rel="3" class="search-choice-close" seq="1" href="javascript:void(0)"></a>

        </li>
        <li id="li_dept_2" ver="old" class="search-choice"><span>QA</span>  <a rel="3" class="search-choice-close" seq="2" href="javascript:void(0)"></a>

        </li>
        <li id="selD7J_chzn_c_3" class="search-choice"><span>sag</span>     <a class="search-choice-close" seq="0.19415735425269753" href="javascript:void(0)"></a>

        </li>
        <li class="search-field"><span contenteditable="true" style="width: 25px;"></span>

        </li>
    </ul>
</div>

如何仅在具有rel属性的锚标记中获取seq?

How to get only seq in anchor tag which have rel attribute?

推荐答案

这是一个相当简单明了的答案:

Here's a fairly simple and straightforward answer:

// gets all anchors with attribute rel and place their [seq] values into an array
var values = $.map($('a[rel]'), function(el){
  return el.getAttribute('seq');
});

console.log(values); // ["1", "2"] 

实时代码示例

这篇关于jQuery在ul li中查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆