我有一个Vimeo网址,如下所示:
<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,然后点击它。我会通过class属性设置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>
答案 0 :(得分: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>
<强>的onclick:强>
$('a').on('click',function(){
$('iframe').attr('src',$(this).data('url'));
});
答案 1 :(得分: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;
});