获取一些嵌入式元素

时间:2011-02-11 13:52:30

标签: jquery html

在下面的html中,如何通过给定的类选择/获取日期?

<div class="blockCarouselAbsoluteSalons blockCarouselAbsolute" id="myCarousel">
    <ul class="carousel">
        <li class="carousel-elem needed">
            <div class="date" style="background-color:red;">
                <p>1955</p>
            </div>
            <div class="blockGoToElem">
                <a href="ajax/salons_history_text.php?id=12" class="ajaxHistory">
                    <img src="img/aboutus/carousel-img3.png" class="" />
                </a>
                <div class="captionText">
                    <img src="img/px.gif" alt=""/>
                    <span>L’Oréal invents haircolour as we know it today</span>
                </div>
            </div>
        </li>
        <li class="carousel-elem notneeded">
            <div class="date" style="background-color:#5297B3;">
                <p>1959</p>
            </div>
            <div class="blockGoToElem">
                <a href="ajax/salons_history_video.php" class="ajaxHistory"><img src="img/aboutus/carousel-img3.png" class="" /></a>
                <div class="captionText">
                    <img src="img/px.gif" alt=""/>
                    <span>Lorem ipsum</span>
                </div>
            </div>
        </li>
        <li class="carousel-elem notneeded">
            <div class="date" style="background-color:#3C9F9C;">
                <p>1967</p>
            </div>
            <div class="blockGoToElem ">
                <a href="ajax/salons_history_text.php?id=12" class="ajaxHistory"><img src="img/aboutus/carousel-img3.png" class="" /></a>
                <div class="captionText">
                    <img src="img/px.gif" alt=""/>
                    <span>L’Oréal ipsum</span>
                </div>
            </div>
        </li>
        <li class="carousel-elem needed">
            <div class="date" style="background-color:#3C9F4F;">
                <p>1974</p>
            </div>
            <div class="blockGoToElem">
                <a href="ajax/salons_history_text.php?id=12" class="ajaxHistory"><img src="img/aboutus/carousel-img3.png" class="" /></a>
                <div class="captionText">
                    <img src="img/px.gif" alt=""/>
                    <span>L’Oréal invents haircolour as we know it today, fluctuat nec mergitur</span>
                </div>
            </div>
        </li>
        <li class="carousel-elem needed">
            <div class="date" style="background-color:purple;">
                <p>1992</p>
            </div>
            <div class="blockGoToElem">
                <a href="ajax/salons_history_text.php?id=12" class="ajaxHistory"><img src="img/aboutus/carousel-img3.png" class="" /></a>
                <div class="captionText">
                    <img src="img/px.gif" alt=""/>
                    <span>L’Oréal ipsum</span>
                </div>
            </div>
        </li>
    </ul>
</div>

3 个答案:

答案 0 :(得分:0)

使用此选择器#myCarousel .needed .date p

答案 1 :(得分:0)

使用此JQuery脚本:

$('.needed .date').each(function() {
    var date = $(this).find('p').text();
    alert(date);
});

演示:

http://jsfiddle.net/Mutant_Tractor/HVQff/9/

答案 2 :(得分:0)

这应该这样做:

$('#myCarousel .needed').each(function() {
    var date = $(this).find('.date p').text();    
    // do stuff with date
});