Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 来自输入标签的Html5视频源_Javascript_Html_Video_Tags - Fatal编程技术网

Javascript 来自输入标签的Html5视频源

Javascript 来自输入标签的Html5视频源,javascript,html,video,tags,Javascript,Html,Video,Tags,我想制作一个带有文本输入元素的网页,在这里我可以放置一个url,然后按下按钮开始播放来自该url的视频。换句话说,我想让输入的url成为视频标记的源 <!DOCTYPE html> <html> <head> <script> function write(){ document.write(document.getElementById('url').value);

我想制作一个带有文本输入元素的网页,在这里我可以放置一个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>

函数写入(){
document.write(document.getElementById('url').value);
}
输入视频的来源

网址:
试试这段代码

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

非常感谢您的回答,但是当我插入url并单击按钮时,它会给我一个空白页。我会尝试在一段时间内提供一个提琴。呃,为什么没有任何明显的原因就被否决了?!它被否决,因为
value
将为您提供文件名,而不是最初的文件名。浏览器中的文件具有
伪路径
。如果需要,您必须从检索到的文件中创建DataURL。答案是2013年的。您确定createDataUrl已使用5年了吗?而且,投反对票也不会告诉任何人任何事情。