我想调用onYouTubeIframeAPIReady函数,但这不是解雇.我只是frameID在控制台,但其他功能没有被调用.
$(document).ready(function(){
var player;
var ytsrc = $('.video_holder_frame').find('iframe').attr('src');
if (ytsrc) ytsrc = ytsrc.match(/youtube.com\/embed\/([^\\?]*)/i);
if (!ytsrc) return;
var frameID = 'youtube_' + ytsrc[1];
console.log(frameID);
$('.video_holder_frame').find('iframe').attr('id', frameID);
function attachToYoutubeFrame() {
console.log("attachToYoutubeFrame");
function onytplayerStateChange(newState) {
console.log("onytplayerStateChange");
console.log(newState);
};
player = new YT.Player(frameID, {
events: {
"onStateChange": onytplayerStateChange
}
});
};
function onYouTubeIframeAPIReady() {
attachToYoutubeFrame();
};
});
Run Code Online (Sandbox Code Playgroud)