直播平台搭建源码,通过 JS 读取本地图片并预览在页面中
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input id="myInput" type="file" onchange="getFile">
<img id="myImage" src="" alt="">
<script>
document.getElementById("myInput").addEventListener("change", getFile, true)
function getFile(file) {
if (!file) {
return;
}
const {
files
} = file.target;
if (files.length <= 0) return;
const fileReader = new FileReader();
fileReader.readAsDataURL(files[0]);
fileReader.onload = (event) => {
console.log(event);
try {
const {
result
} = event.target;
document.getElementById("myImage").src = result;
} catch (e) {
console.log(e);
}
};
}
</script>
</body>
</html>
以上就是 直播平台搭建源码,通过 JS 读取本地图片并预览在页面中,更多内容欢迎关注之后的文章
标签:读取,预览,JS,直播,源码,页面 From: https://www.cnblogs.com/yunbaomengnan/p/16710854.html