我没有调用onYouTubeIframeAPIReady()函数。我有div为你管视频
<div class="panel-body custom-content-part"></div>
这是使用
的jquery代码 var html = '<iframe id="ik_player_iframe" frameborder="0" src="http://www.youtube.com/embed/' +
videoId +'??enablejsapi=1&version=3" width="100%" height="420"></iframe>';
$('#content-view .custom-content-part').html(html);
//Holds a reference to the YouTube player
var ik_player;
//this function is called by the API
function onYouTubeIframeAPIReady() {
//creates the player object
ik_player = new YT.Player('ik_player_iframe');
console.log('Video API is loaded');
//subscribe to events
ik_player.addEventListener("onReady","onYouTubePlayerReady");
ik_player.addEventListener("onStateChange","onYouTubePlayerStateChange");
}
function onYouTubePlayerReady() {
console.log('Video is ready to play');
}
function onYouTubePlayerStateChange(event) {
console.log('Video state changed');
}
某种方式onYouTubeIframeAPIReady的方法永远不会被触发。