我試圖在本地運行的jsfiddle代碼,特別是這一個: http://jsfiddle.net/BAqTe/如何從本地運行jsfiddle中保存的html?
我環顧四周,人們建議使用「/秀」並保存頁面,加載的依賴,但它不」 t本地工作的我。我有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>
問題可能出現在錯誤信息中 - 也請確保在網絡活動中查找非正常響應。對於初學者,我會使用外部CDN來加載標準庫,比如jQuery。 – user2246674 2013-04-25 00:31:44
@ user2246674:你在說什麼錯誤信息? – Aravind 2013-04-25 00:49:55