从链接读取rel值并使用JQuery追加到div

时间:2010-06-30 05:14:54

标签: jquery append

我希望阅读锚点的rel值,并在点击从Youtube加载到我的播放器的视频中的链接时将其附加到div。下面是一个快速代码转储。单击链接时,rel值应附加到视频标题div。谢谢!

<div class="video">
<a onclick="player('http://www.youtube.com/v/ylJOn4dEKo0')" href="javascript:void(0);" rel="This is video one.">Video 1</a>
</div>

<div class="video">
<a onclick="player('http://www.youtube.com/v/gXRbiqm-HJA')" href="javascript:void(0);" rel="This is video two.">Video 2</a>
</div>

<div id="video-container">Video plays here</div>
<div class="video-caption">Video caption appended here</div>
</div>

3 个答案:

答案 0 :(得分:2)

这样的事情可以让你摆脱困境:

$(function()
{
    $('div[class=video] > a').click(function() 
    {
        $('div.video-caption').html($(this).attr('rel'));
    });
});

答案 1 :(得分:0)

你去......

<div class="video">
<a onclick="player('http://www.youtube.com/v/ylJOn4dEKo0');UpdateTitle(this);" href="javascript:void(0);" rel="This is video one.">Video 1</a>
</div>

<div class="video">
<a onclick="player('http://www.youtube.com/v/gXRbiqm-HJA');UpdateTitle(this);" href="javascript:void(0);" rel="This is video two.">Video 2</a>
</div>

JS:

function UpdateTitle(obj)
{
   $(".video-caption").html($(obj).attr("rel"));
}

答案 2 :(得分:0)

这段代码对我来说很好

<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>    
<script type="text/javascript">
     $(function () {
         $(".video a").click(function () {
             $(".video-caption").text($(this).attr("rel"));
         });

     });
</script>