我正在尝试在本地运行一个jsfiddle代码,特别是这个: http://jsfiddle.net/BAqTe/
我环顾四周,人们建议使用“/ show”并保存页面,并加载依赖项,但它不能在本地工作。我有jquery.1.8.3并且我已经包含了它。然而,“onYouTubeIframeAPIReady”永远不会被调用。我需要在本地运行它吗?这是我到目前为止的代码。
<html>
<head>
<script type='text/javascript' src="jquery.js"></script>
<script type='text/javascript'>
//<![CDATA[
$(window).load(function(){
// Add the API
var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Register the player
var player;
onYouTubeIframeAPIReady = function() {
player = new YT.Player('ytplayer', {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// Add some controls (they can't be called before onPlayerReady in real life)
$('#play').click(function() {
player.playVideo();
});
$('#pause').click(function() {
player.pauseVideo();
});
});
//]]>
</script>
</head>
<body>
<iframe class="video-frame" id="ytplayer" src="http://www.youtube.com/embed/RP4abiHdQpc?controls=0&showinfo=0&enablejsapi=1" frameborder="0"></iframe>
<button id="play">Play</button>
<button id="pause">Pause</button>
</body>
</html>
答案 0 :(得分:0)
onYouTubeIframeAPIReady = function() {
player = new YT.Player('ytplayer', {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
onYouTubeIframeAPIReady
可能会被调用,但有错误,因为onPlayerReady
和onPlayerStateChange
未被定义为函数。
从jsfiddle复制两个缺失的函数,或者不将它们包含为事件。