简体   繁体   English

jQuery如何在div中选择所有节点文本

[英]jQuery How to select all nodes text in div

I have a div like this: 我有这样的股利:

<div class="movie">

    Date: 
    <span class="date"> June 12, 1987 </span>

    Título: 
    <span class="title">
        <a class="select_movie" href="#">
            Predator
        </a>        
    </span>

    Director: <span class="director">John McTiernan</span>

    Starring: <span class="starring">Arnold Schwarzenegger</span>

</div> 

I want all the text nodes in <div class="movie"> , after the click of a link .select_movie 单击链接.select_movie后,我希望<div class="movie">所有文本节点。

$('.select_movie').click(function(){
    ..........
    ..........
});

at the end I need to retrieve the value of the nodes to be assigned to a variables, like this: 最后,我需要检索要分配给变量的节点的值,如下所示:

var date = June 12, 1987;

var title = Predator;

var director = John McTiernan;

var starring = Arnold Schwarzenegger;

Try this in order to get each of the values: 尝试此操作以获取每个值:

$('.select_movie').click(function(){
    var movie = $(this).closest(".movie");
    var date = $(movie).find(".date").text();
    var title = $(movie).find(".title .select_movie").text();
    var director = $(movie).find(".director").text();
    var starring = $(movie).find(".starring").text();
});

Fiddle : http://jsfiddle.net/unwgeqce/1/ 小提琴http : //jsfiddle.net/unwgeqce/1/

每个var都是这样的:

var date = $('.movie').find('.date').text();

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

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