2013-07-25 50 views
1

我想知道它是如何可能使用jQuery或JavaScript如何動態地使用jQuery或JavaScript

我試過的jQuery但unscuccessful使用對象的標籤添加到HTML5視頻標籤對象的標籤添加到HTML5視頻標籤(無法在IE8及以下瀏覽器觀看視頻)以下

是我的代碼

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script type="text/javascript"> 
     $(document).ready(function(){ 
      var configval= "config={'playlist':['http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg',{'url':'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4','autoPlay':false}]}"; 

      var $source = $('<object type="application/x-shockwave-flash" width="640" height="360">'+ 
          '<param name="movie" value="http://api.html5media.info/1.1.5/flowplayer.swf" />'+ 
          '<param name="flashVars" value="1" />'+ 
          '</object>'+ 
          '<p>need to install quick time player to play videos</p>'); 
      $source.find('param[name="flashVars"]').attr('value', configval); 
      var $video = $('<video controls="controls" poster="http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg" width="640" height="360"></video>').append($source); 

      $('body').append($video); 
     }) 
    </script> 

回答

1

我已經編輯我的答案爲簡單起見,基於Katana314的評論。我認爲這是你要找的。您錯過了視頻標籤內的視頻src(您也可以使用嵌套在視頻標籤內的源標籤定義多個源視頻編碼)。

您試圖在視頻標籤內追加對象標籤的方式並不完全正確,因此您只需要這樣做,否則您就處於正確的軌道上。

我沒有IE8的時刻進行測試,但這應該工作:

<script type="text/javascript"> 
    $(document).ready(function(){ 
     var configval= "config={'playlist':['http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg',{'url':'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4','autoPlay':false}]}"; 

     var $source = $('<object type="application/x-shockwave-flash" width="640" height="360">'+ 
         '<param name="movie" value="http://api.html5media.info/1.1.5/flowplayer.swf" />'+ 
         '<param name="flashVars" value="1" />'+ 
         '</object>'+ 
         '<p>need to install quick time player to play videos</p>'); 
     $source.find('param[name="flashVars"]').attr('value', configval); 

     //Added source of your video here 
     var $video = $('<video src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" controls="controls" poster="http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg" width="640" height="360"></video>'); 

     $('body').append($video); 

     //append source inside of the video tag 
     $('video').append($source); 
    }) 
</script> 
+0

做功能檢測和分割代碼聽起來像一個有效的選項。儘管如此,我想不出user12345zomg的方法行不通的具體原因;通常,當瀏覽器不識別「」或「