0

我有一个看起来像这样的 Vimeo URL:

<iframe src="https://player.vimeo.com/video/57418480?byline=0&portrait=0&autoplay=1" width="620" height="350" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

我想要做的是获取视频 ID,在本例中为 57418480 并将其替换为 onclick。我将通过类属性设置 ID。例如:

<li><a href="#" class="57418481">Ethics in Investing</a></li>

单击上面的链接将仅替换数字 ID,因此它将如下所示:

<iframe src="https://player.vimeo.com/video/57418481?byline=0&portrait=0&autoplay=1" width="620" height="350" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
4

2 回答 2

2

在链接中使用 data-url

<li><a href="#" data-url="https://player.vimeo.com/video/57418481?byline=0&portrait=0&autoplay=1" class="57418481">Ethics in Investing</a></li>

点击:

$('a').on('click',function(){
  $('iframe').attr('src',$(this).data('url'));
});
于 2013-04-21T18:54:41.613 回答
1
$('a').click(function() {
    var newID = $(this).attr('class');
    var newURL = 'https://player.vimeo.com/video/' + newID + '?byline=0&portrait=0&autoplay=1';
    $('iframe').attr('src',newURL);
    return false;
});

http://jsfiddle.net/Khpd7/

于 2013-04-21T19:07:54.530 回答