gpt4 book ai didi

php - 使用 jquery 动态更改 javascript youtube 播放器的 href

转载 作者:行者123 更新时间:2023-11-30 05:48:33 26 4
gpt4 key购买 nike

    <a id="bgndVideo" href="http://www.youtube.com/watch?v=mAf6zKRb1wI" 
class="movie {opacity:.8, isBgndMovie:{width:'window',mute:false}, o
ptimizeDisplay:true, showControls:true, ratio:'4/3', loop: true}">vito
acconci theme song 1973</a>

以上是我在我的文档中使用的 html 嵌入 javascript chromeless youtube 播放器作为背景。我从 http://pupunzi.com/mb.components/mb.YTPlayer/demo/demo_background.html 得到代码

href 控制设置为背景的视频我想用常量动态更改上面html 的href。

我尝试过的:

var DATA = VideoID

$("bgndVideo").attr("href", DATA)

这没用,也没用

document.getElementById("bgndVideo").href=DATA;

这也没有用。有什么建议么?在上面的示例站点上查看源代码可能是个好主意,以便更好地理解我的意思,我发现很难正确表达我的问题!

最佳答案

您不能通过更改 href 来更改电影。它已经被使用,并且在您初始化播放器后立即不再对播放器可用。如果您在初始之前更改 URL,那么是的,但这可能不是您想要的。

看这里:

https://github.com/pupunzi/jquery.mb.YTPlayer/wiki

$.fn.changeMovie(URL, opt)

This method let you change the video of the specified player passing a new parameter object to set specific properties.

这是我对你的代码的看法

$('#bgndVideo').changeMovie('http://www.youtube.com/watch?v='+DATA, {opacity:.4, ratio:'16/9'});

不过我认为你可能想要这个:

var movies = [
{"id":"mAf6zKRb1wI","title":"Vito Acconci theme song 1973 -- part 1"},
{"id":"2MxhNdyADEU","title":"Vito Acconci theme song 1973 -- part 2"},
{"id":"xOsWwpzqlZw","title":"Vito Acconci theme song 1973 -- part 3"}
]; // note no comma after the last

$(function() {
$.each(movies,function() {
$("#container").append('<button data-id="'+
$(this).id+'" class="buttons">'+
$(this).title+'</button>');
});
$(".buttons").on("click", function() {
$("#bgndVideo").changeMovie("http://www.youtube.com/watch?v="+
$(this).data("id"), {opacity:.4, ratio:"16/9"});
});
});

关于php - 使用 jquery 动态更改 javascript youtube 播放器的 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16267687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com