我有一个如下所示的 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>
最佳答案
在链接中使用 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'));
});
关于javascript - jQuery 替换部分 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16134916/