将此迭代存储在.each函数中

时间:2010-11-10 14:18:25

标签: jquery

您好我正在尝试构建一个youtube脚本..

我几乎让它工作正常,但我的视频的src网址总是引用最后一次迭代..我不知道如何让它存储这个迭代,这是正确的。

这就是我所拥有的:

Jquery的:

$('.tubeWrapper').each(function() {
var tubeurl = $(".dooTubeUrl",this).text();
var thumb = $.jYoutube(tubeurl , 'small');
$(".dooTube_ThumbLink",this).append("<img src=' " + thumb + " ' />");

var url = tubeurl;
$result = getList(url, "v");
// It is this next line that seems to be the problem, allways references the last iteration as expected, but wrong.
$(".youtube-player",this).attr("src","http://www.youtube.com/embed/" + $result);
});


$('.dooTube_ThumbLink').click(function() {
$(".dooTubeWindow").doo_lightbox();
});

HTML:

<div class="tubeWrapper">
<div class="dooTubeUrl">http://www.youtube.com/watch?v=aA3dHi_o7Yw&feature=related</div>

<div class="dooTube_ThumbLink"><div class="dooTube_Arrow"></div></div>
<div class="dooTubeWindow">
    <iframe title="YouTube video player" 
class="youtube-player" 
type="text/html" 
width="480" height="390"
src="" frameborder="0">
</iframe>
</div> 

</div>

<div class="tubeWrapper">
<div class="dooTubeUrl">http://www.youtube.com/watch?v=Xvj4Ud-RKrM&feature=related</div>

<div class="dooTube_ThumbLink"><div class="dooTube_Arrow"></div></div>
<div class="dooTubeWindow">
    <iframe title="YouTube video player" 
class="youtube-player" 
type="text/html" 
width="480" height="390"
src="" frameborder="0">
</iframe>
</div> 

</div>

1 个答案:

答案 0 :(得分:0)

你可能在$ result之前缺少var:

var $result = ...