我有这样的代码:
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player_rfIuA8wXD8c;
function onYouTubePlayerAPIReady() {
player_YdfNuwMhMg4 = new YT.Player('player_rfIuA8wXD8c', {
height: '435',
width: '480',
videoId: 'rfIuA8wXD8c',
playerVars: {
'start': 56,
'autoplay': 0,
'controls': 1,
'playlist': 'rfIuA8wXD8c',
'loop': 1
}
});
}
var player_HmZKgaHa3Fg;
function onYouTubePlayerAPIReady() {
player_HmZKgaHa3Fg = new YT.Player('player_HmZKgaHa3Fg', {
height: '480',
width: '640',
videoId: 'HmZKgaHa3Fg',
playerVars: {
'start': 0,
'autoplay': 0,
'controls': 1,
'playlist': 'HmZKgaHa3Fg',
'loop': 1
}
});
}

<div class="content">
<div id="player_rfIuA8wXD8c" class="swipebox" rel="yt"></div>
<span>test text</span>
<div id="player_HmZKgaHa3Fg" class="swipebox" rel="yt"></div>
</div>
&#13;
...仅制作最后一部电影(HmZKgaHa3Fg
)。我尝试了不同的方法,但我仍然无法拍摄第一部电影。有没有人有类似的问题,可以建议我做错了什么?感谢所有帮助
答案 0 :(得分:0)
报废。
可能是这条线吗?
player_YdfNuwMhMg4 = new YT.Player('player_rfIuA8wXD8c', {
你有player_YdfNuwMhMg4,但我在其他任何地方都没有看到它?
答案 1 :(得分:0)
您已声明了两个函数onYouTubePlayerAPIReady()
,您只需要实例化一个函数并在其中声明YT.Player
:
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var players = new Array();
var players_attr = new Array();
players_attr["player_rfIuA8wXD8c"] = {
height: '435',
width: '480',
videoId: 'rfIuA8wXD8c',
playerVars: {
'start': 56,
'autoplay': 0,
'controls': 1,
'playlist': 'rfIuA8wXD8c',
'loop': 1
}
};
players_attr["player_HmZKgaHa3Fg"] = {
height: '480',
width: '640',
videoId: 'HmZKgaHa3Fg',
playerVars: {
'start': 0,
'autoplay': 0,
'controls': 1,
'playlist': 'HmZKgaHa3Fg',
'loop': 1
}
};
function onYouTubeIframeAPIReady() {
for (key in players_attr) {
players[key] = new YT.Player(key, players_attr[key]);
}
}
<div class="content">
<div id="player_rfIuA8wXD8c" class="swipebox" rel="yt"></div>
<span>test text</span>
<div id="player_HmZKgaHa3Fg" class="swipebox" rel="yt"></div>
</div>