的Youtube JavaScript和多个视频API(ASP)
问题描述:
我有我的ASP页面上生成的嵌入代码如下:的Youtube JavaScript和多个视频API(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);
}
任何帮助吗?谢谢。
答
两个问题:
- 使用
document.getElementById
(用大写字母)。 - 使用
==
至比较变量,不是=
。
代码:
var vid_left, vid_right;
function onYouTubePlayerReady(id) {
alert(id);
if (id == 'ytplayer_right') {
vid_right = document.getElementById(id);
alert(vid_right);
} else if(id == 'ytplayer_left') {
vid_left = document.getElementById(id);
alert(vid_left);
}
}
答
我不知道,你可以得到标签用的getElementById。试试:
var object = document.getElementById(objectID)
var embed = object.getElementsByTagName('embed')[0];
+0
是的,他可以。定义了HTML'id'属性,并且['document.getElementById'](https://developer.mozilla.org/en/DOM/document.getElementById)得到了很好的支持。 – 2012-04-08 10:39:28
'getElementById'。适当的情况下。 – 2012-04-08 10:18:32
改变它,没有区别 – Michael 2012-04-08 10:22:22