我需要在 JavaScript 中将值从一个函数传递给另一个函数,但是当我尝试这样做时,它不起作用。问题在于floaded2()
获取theYoutubeGlobalState
.
HTML:
<html>
<head>
<script src = "http://www.youtube.com/player_api"></script>
<script src = "jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="style.css" type="text/css" media="screen" charset="utf-8">
</head>
<body dir = "rtl">
<iframe src="http://www.youtube.com/embed/-cSFPIwMEq4" onload="floaded2()" title="YouTube video player" id="player" allowfullscreen="" frameborder="0" height="400" width="500"></iframe>
</body>
</html>
JavaScript:
var theYoutubeGlobalState;
//onYouTubePlayerAPIReady
function floaded() {
player = new YT.Player('player', {
videoId: '-cSFPIwMEq4',
events: {
'onStateChange': function (event) {
theYoutubeGlobalState=event.data; }
}
});
}
function floaded2() {
switch ( theYoutubeGlobalState )
{
case 0:
alert("Ended");
break;
case 1:
alert("Playing");
break;
case 2:
alert("Paused");
break;
}
}
你可以检查一下:http: //jsfiddle.net/3GGHW/1/。你能告诉我有什么问题吗?