2012-08-03 5 views
-3

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/. 문제가 무엇인지 말해 주실 수 있습니까?

+0

이것은별로 도움이되지 않습니다. 어떤 함수 또는 어떤 값을 언급하지 않습니다. 더욱이, Fiddles를 사용하면 JS를 HTML로 묶기보다는 JS 전용 패널에 배치하십시오. 질문의 일부로 코드를 게시하는 것이 도움이됩니다. 도움을 청하기 위해 * 클릭해서는 안됩니다. – Utkanos

+0

위와 같이 어떤 값과 함수가 유용 할 지 말하면 도움이됩니다. – zik

답변

0

는 내가 여기서 일했다 :

http://jsfiddle.net/3GGHW/2/

당신은 HTML의 onload 이벤트 핸들러에 잘못된 기능을 설정 - floaded()하지 floaded2() 할 필요가 - 당신은 floaded()에서 floaded2()를 호출 할 필요 . 그게 전부 야.

0

floaded()을 전혀 호출하지 않은 것으로 보입니다. 앞으로는 [reduced] 테스트 케이스를 직접 질문에 붙여 넣으십시오.

관련 문제