0

我正在尝试在本地运行 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>
4

1 回答 1

0
onYouTubeIframeAPIReady = function() {
   player = new YT.Player('ytplayer', {     
                  events: {
         'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
                          }
                         });
                        }

onYouTubeIframeAPIReady可能会被调用,但有错误,因为onPlayerReadyonPlayerStateChange未定义为函数。

从您的 jsfiddle 复制两个缺少的函数,或者不将它们包含为事件。

于 2013-04-25T01:47:27.880 回答