2012-04-08 44 views
1

我有我的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); 
     } 

任何帮助吗?谢谢。

+0

'getElementById'。适当的情况下。 – 2012-04-08 10:18:32

+0

改变它,没有区别 – Michael 2012-04-08 10:22:22

回答

1

两个问题:

代码:

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); 
    } 
} 
+0

非常感谢,工作正常。我刚刚开始使用JavaScript,所以我并不感到惊讶,我犯了基本错误... – Michael 2012-04-08 10:40:43

+0

@Michael JavaScript是一种区分大小写的语言。如果您需要一本出色的指南,请参阅https://developer.mozilla.org/en/JavaScript/Guide。本网站也是互联网上最好的JavaScript参考之一。 – 2012-04-08 10:42:13

+0

我会看看,非常感谢您的帮助 – Michael 2012-04-08 10:47:21

0

我不知道,你可以得到标签用的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