1

我想制作一个带有文本输入元素的网页,我可以在其中放置一个 url,然后按下按钮开始从该 url 播放视频。换句话说,我想让输入中的 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>
4

1 回答 1

-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>
于 2013-06-19T08:37:24.307 回答