来自输入标签的Html5视频源

时间:2013-06-19 08:20:23

标签: javascript html5 video tags

我想创建一个带有文本输入元素的网页,我可以在其中放置网址并按下按钮以开始播放该网址中的视频。换句话说,我想让输入中的url成为视频标记的来源。

<!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 个答案:

答案 0 :(得分:-2)

试试此代码

<!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>