我是 Jquery 的新手。我正在尝试使用两个按钮嵌入单个视频:播放和停止。我注意到,如果我将代码的 videoid 变量替换为真实的视频 id(例如 CkPv2jP9KeY)直接放在 html 内容上,播放和停止按钮就会起作用。到目前为止,我有这个:
<!DOCTYPE html>
<html lang="es">
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://www.youtube.com/player_api"></script>
<script>
var player;
function onYouTubeIframeAPIReady() {player = new YT.Player('player');}
if(window.opera){
addEventListener('load', onYouTubeIframeAPIReady, false);
}
</script>
</head>
<body>
<script>
$(document).ready(function(){
$.getJSON("https://gdata.youtube.com/feeds/api/users/diasporaduo/uploads?v=2&alt=jsonc",function(json){
videoid = json.data.items[0].id;
$("#video").append('<iframe id="player" width="560" height="349" frameborder="0" src="http://www.youtube.com/embed/'+ videoid +'?rel=0&wmode=Opaque&enablejsapi=1"></iframe>');
});
});
</script>
<div id="video"></div>
<a href="javascript: void(0)" onclick="player.playVideo(); return false">play</a><br>
<a href="javascript: void(0)" onclick="player.stopVideo(); return false">stop</a>
</body>
</html>