2013-06-19 42 views
0

我想製作一個帶有文本輸入元素的網頁,我可以放置一個網址並按下按鈕開始播放來自該網址的視頻。換句話說,我想讓輸入中的url成爲視頻標籤的來源。來自輸入標籤的Html5視頻源

<!DOCTYPE html> 
<html> 
    <head> 
     <script> 
      function write(){ 
       document.write(document.getElementById('url').value); 
      } 
     </script> 
    </head> 
    <body> 

     <p>Enter the source of the video.</p> 

     <form id="frm1"> 
      URL: <input id="url" type="text" name="fname"><br> 
      <input type="button" onclick="write()" value="Please Write the URL"> 
     </form> 

    </body> 
</html> 

回答

-1

試試這個代碼

<!DOCTYPE html> 
    <html> 
    <head></head> 
    <body> 
     <p>Enter the source of the video.</p> 
     <form id="frm1"> 
      URL: <input id="url" type="text" name="fname"><br> 
      <input type="button" onclick="write()" value="Please Write the URL"> 
     </form> 
     <video id="myVideo" controls> 
      <source src="foo.ogg" type="video/ogg; codecs=dirac, speex"> 
      Your browser does not support the <code>video</code> element. 
     </video> 
    <script> 
     function write() 
     { 
      var vid = document.getElementById('myVideo'); 
      vid.src = document.getElementById('url').value; 
      vid.play(); 
     } 
    </script> 
</body> 
</html> 
+0

非常感謝你回答,但是當我插入網址,然後點擊按鈕它給了我的空白頁。 –

+0

您的控制檯是否會拋出任何錯誤? –

+0

我會盡量在一段時間內提供一個小提琴。 –