0

我想为特定类的所有秒元素绑定一个点击事件,我正在使用;

$("ul.message-list-row > li:eq(1) > div").click(function(){...});

不幸的是,它不起作用。我也试过没有“>”但没有运气。

我的代码中有 7 个相同的 UL。所以,

console.log($("ul.message-list-row").length);

返回 7,但是

console.log($("ul.message-list-row > li:eq(1)").length);

返回 1。不应该是 7 吗?错误是什么?

顺便说一句,我正在尝试使用以下标记;

<ul class="message-list-row rounded-corners">
    <li>
        <img src="Public/CSS/Images/sample-app-icon-02.png" alt="" title="" />
        <span class="app-name">AppName</span>
        <span class="version">V3.1</span>
        <div class="apple">OS V. - 5.04</div>
    </li>
    <li>
        <div>
            <span>Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Nulla vitae elit libero, a pharetra augue. Maecenas sed diam eget risus varius blandit sit amet non magna.Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Nulla vitae elit libero, a pharetra augue. Maecenas sed diam eget risus varius blandit sit amet non magna.</span>
        </div>
    </li>
    <li>
        <div class="progress-bar" title="70"></div>
        <span>%70</span>
    </li>
    <li class="number">7643</li>
    <li class="completed">&nbsp;</li>
    <li>&nbsp;</li>
    <li>
        <ul>
            <li>Language:</li>
            <li>
                <img src="Public/CSS/Images/flag-uk.png" alt="" title="" />
                English
            </li>

            <li>Operator:</li>
            <li>Operator</li>

            <li>Country:</li>
            <li>
                <img src="Public/CSS/Images/flag-tr.png" alt="" title="" />
                Country
            </li>

            <li>Badge:</li>
            <li>Clean</li>
        </ul>
    </li>
</ul>


<ul class="message-list-row rounded-corners">
    <li>
        <img src="Public/CSS/Images/sample-app-icon-03.png" alt="" title="" />
        <span class="app-name">AppName</span>
        <span class="version">V3.1</span>
        <div class="apple">OS V. - 5.04</div>
    </li>
    <li>
        <div>
            <span>Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Nulla vitae elit libero, a pharetra augue. Maecenas sed diam eget risus varius blandit sit amet non magna.Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Nulla vitae elit libero, a pharetra augue. Maecenas sed diam eget risus varius blandit sit amet non magna.</span>
        </div>
    <li>
        <div class="progress-bar" title="0"></div>
        <span>%0</span>
    </li>
    <li class="date">00:22:58</li>
    <li class="waiting">&nbsp;</li>
    <li>
        <a class="settings-button" href=""></a>
        <a class="approve-button action-button" href=""></a>
        <a class="cancel-button action-button" href=""></a>
    </li>
    <li>
        <ul>
            <li>Language:</li>
            <li>
                <img src="Public/CSS/Images/flag-uk.png" alt="" title="" />
                English
            </li>

            <li>Operator:</li>
            <li>Operator</li>

            <li>Country:</li>
            <li>
                <img src="Public/CSS/Images/flag-tr.png" alt="" title="" />
                Country
            </li>

            <li>Badge:</li>
            <li>Clean</li>
        </ul>
    </li>
</ul>
4

1 回答 1

1

:eq()不像你想象的那样工作。使用:nth-child(2)而不是:eq(1).

:nth-child选择器获取 jQuery 集合中作为其父级的第 n 个子级的每个元素。选择:eq器只获取 jQuery 集合中的一个元素,即“第 n 个”(0 索引)元素。

http://jsfiddle.net/mattball/xhYaP/

于 2012-08-16T04:10:45.153 回答