我已经让 ASP 在我的页面上生成嵌入代码,如下所示:
Table1.Rows(0).Cells(0).Text = "<object style=""height: 390px; width: 640px"" id=""ytplayer_object_left"">" & _
"<param name=""movie"" value=""https://www.youtube.com/v/UASyS-jUKKI?version=3&feature=player_embedded&controls=0&enablejsapi=1&showinfo=0&iv_load_policy=3&playerapiid=ytplayer_left"">" & _
"<param name=""allowfullscreen"" value=""true"">" & _
"<param name=""allowscriptaccess"" value=""always"">" & _
"<embed src=""https://www.youtube.com/v/UASyS-jUKKI?version=3&feature=player_embedded&controls=0&enablejsapi=1&showinfo=0&iv_load_policy=3&playerapiid=ytplayer_left"" type=""application/x-shockwave-flash"" allowfullscreen=""true"" allowscriptaccess=""always"" width=""425"" height=""344"" id=""ytplayer_left""></object>"
Table1.Rows(0).Cells(2).Text = "<object style=""height: 390px; width: 640px"" id=""ytplayer_object_right"">" & _
"<param name=""movie"" value=""https://www.youtube.com/v/uasys-jukki?version=3&feature=player_embedded&controls=0&enablejsapi=1&showinfo=0&iv_load_policy=3&playerapiid=ytplayer_right"">" & _
"<param name=""allowfullscreen"" value=""true"">" & _
"<param name=""allowscriptaccess"" value=""always"">" & _
"<embed src=""https://www.youtube.com/v/uasys-jukki?version=3&feature=player_embedded&controls=0&enablejsapi=1&showinfo=0&iv_load_policy=3&playerapiid=ytplayer_right"" type=""application/x-shockwave-flash"" allowfullscreen=""true"" allowscriptaccess=""always"" width=""425"" height=""344"" id=""ytplayer_right""></object>"
我已确保两者的 ID 不同,并且两者都正确调用了 onYouTubePlayerReady(id)(返回“ytplayer_left”和“ytplayer_right”)。但是,我无法将每个视频作为不同的 javascript 变量,因此我可以独立播放/暂停它们。
这是我尝试过的代码:
var vid_left;
var vid_right;
function onYouTubePlayerReady(id) {
alert(id);
if (id = 'ytplayer_right') {
vid_right = document.getelementbyId(id);
alert(vid_right);
}
if(id = 'ytplayer_left') {
vid_left = document.getelementbyId(id);
alert(vid_left);
}
有什么帮助吗?谢谢。