function t() {
var u = document.getElementById("fileupload").value;
var video = document.getElementById('video');
document.getElementById.scr = u;
video.load();
video.play();
};
<button id="submit" value="submit" onclick="t();">play</button>
<embed id="video" width="330" height="220" scr="">
答案 0 :(得分:0)
您无法使用其src或id直接阅读或播放视频。
您必须执行以下类似操作才能完成您的要求。
使用FileReader
函数从input type file
<script>
function t() {
var preview = document.querySelector('embed');
var video = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
reader.onloadend = function () {
preview.src = reader.result;
}
if (video) {
reader.readAsDataURL(video);
} else {
preview.src = "";
}
//video.load();
//video.play();
};
</script>
<input type="file" name="fileupload" value="fileupload" id="fileupload">
<label for="fileupload"> Select a file to play</label>
<embed id="video" width="330" height="220" scr="">
<button id="submit" value="submit" onclick="t();">play</button>
这里是JSFiddle