2012-11-11 116 views
0

我試圖實時更改YouTube視頻,但即時獲取無處; 在我的代碼中,當我第一次點擊'li'元素時,視頻加載正確,但是如果我嘗試再次單擊視頻不更新; 這裏是我的代碼:jQuery YouTube視頻更新視頻

function loadv(v) 
    { 
    var params = { 
      allowScriptAccess: "always" 
     }; 

     var atts = { 
      id: "ytplayer1" 
     }; 




    swfobject.embedSWF("http://www.youtube.com/v/"+v+"?rel=0&enablejsapi=1&playerapiid=ytplayer1", 
         "play", "480", "295", "9", null, null, params, atts); 

    } 


    $('#playlist li').click(function() 
    { 

      var video = $(this).attr('id'); 
      loadv(video); 
      console.log(video); //shows the correct id 

     }); 

和HTML:

<div id="play">You need Flash and JavaScript in order to view the video.</div> 
    <div id="videoStatus">status</div> 


     </br> 
     <ul id="playlist"> 
    <li id="C0DPdy98e4c">1</li> 
    <li id="zM0k99OpiXM">2</li> 
    <li id="0ScsDReUTxw">3</li> 
    <li id="crgB4TyzyXM">4</li> 
    </ul> 

回答