1 回答
TA贡献1744条经验 获得超4个赞
有点破解,但可能会给你你需要的东西
var myfile={name:"none"};
function read(input) {
var file = input.files[0];
var idxDot = file.name.lastIndexOf(".") + 1;
var extFile = file.name.substr(idxDot, file.name.length).toLowerCase();
var span =document.getElementById('last');
if (extFile=="jpg" || extFile=="jpeg" || extFile=="png"){
//fileContent = await readFile(file);
myfile=file
alert("Valid file selected!");
span.style.display='none';
}else{
alert("Only jpg, jpeg or png allowed");
input.value = '';
span.style.display='inline';
span.innerHTML = "Last valid File was: " + myfile.name
}
}
span{
display:none;
}
<!DOCTYPE html>
<html>
<body>
<input type="file" align="center" accept=".jpg,.jpeg,.png" onchange="this.size = Math.max(this.value.length, 7)+15;read(this)" id="myinput" style="min-width: 50px;"
/>
<span id='last'></span>
</body>
</html>
- 1 回答
- 0 关注
- 91 浏览
添加回答
举报