我有这样的div:
<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>
点击链接<div class="movie">
.select_movie
中的所有文字节点
$('.select_movie').click(function(){
..........
..........
});
最后我需要检索要分配给变量的节点的值,如下所示:
var date = June 12, 1987;
var title = Predator;
var director = John McTiernan;
var starring = Arnold Schwarzenegger;
答案 0 :(得分:2)
尝试以获取每个值:
$('.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();
});
答案 1 :(得分:0)
每个var都是这样的:
var date = $('.movie').find('.date').text();