<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>文件上传预览</title>
</head>
<body>
<input type="file" id="zzz">
<video id="bbb" src="" controls="controls"></video>
<img src="" id="ccc" alt="">
<textarea name="" id="aaa" cols="30" rows="10"></textarea>
<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#zzz').change(function(){
var reader = new FileReader()
reader.readAsDataURL(this.files[0])
reader.onload=function(){
console.log(this.result.indexOf('data:image'))
if(this.result.indexOf('data:image') != -1){
$('#ccc').attr('src',this.result)
}
if(this.result.indexOf('data:video') != -1){
$('#bbb').attr('src',this.result)
}
$('#aaa').val(this.result)
}
})
})
</script>
</body>
</html>
input上传文件预览
最新推荐文章于 2024-07-12 15:49:20 发布