美文网首页
video预览本地视频

video预览本地视频

作者: 空天啸鹤 | 来源:发表于2019-05-06 19:30 被阅读0次

https://zhidao.baidu.com/question/1368028790248827179.html

<div class="content">
<input id="v_file" type="file" style="display:none;" onChange="play()"/>
<button id="play" onClick="yincang()">播放</button>
<video id="video_id" controls autoplay></video>
</div>
<script>
function yincang(){
var v_file=document.getElementById('v_file');
v_file.click();
}
function play(){
var file = document.getElementById('v_file').files[0];
var url = URL.createObjectURL(file);
console.log(url);
document.getElementById("video_id").src = url;

}
</script>
用display把input隐藏起来,然后注册一个click事件,这样就完成了你想要的功能。。
不知道我是不是理解错了你的需求
这个是你想要的答案吗

相关文章

网友评论

      本文标题:video预览本地视频

      本文链接:https://www.haomeiwen.com/subject/vvadoqtx.html