1

次のように、ページに埋め込みコードを生成する 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);
        }

何か助けはありますか?ありがとう。

4

2 に答える 2

1

2 つの問題:

  • 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);
    }
}
于 2012-04-08T10:27:57.523 に答える
0

getElementById でタグを取得できるかどうかわかりません。試す:

var object = document.getElementById(objectID)

var embed = object.getElementsByTagName('embed')[0];
于 2012-04-08T10:32:27.827 に答える