JavaScript에서 한 함수에서 다른 함수로 값을 전달해야하지만이 작업을 수행하려고하면 작동하지 않습니다. theYoutubeGlobalState
의 값을 가져 오는 기능이 floaded2()
인 경우 문제가 발생합니다.변수를 다른 함수로 전달하지 않음
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>
자바 스크립트는 :
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/. 문제가 무엇인지 말해 주실 수 있습니까?
이것은별로 도움이되지 않습니다. 어떤 함수 또는 어떤 값을 언급하지 않습니다. 더욱이, Fiddles를 사용하면 JS를 HTML로 묶기보다는 JS 전용 패널에 배치하십시오. 질문의 일부로 코드를 게시하는 것이 도움이됩니다. 도움을 청하기 위해 * 클릭해서는 안됩니다. – Utkanos
위와 같이 어떤 값과 함수가 유용 할 지 말하면 도움이됩니다. – zik