我正在使用javascript的FileReader和我的自定义函数来读取JPG-JPEG图像,我的问题是如何通过下面的代码检测文件扩展名,如果文件不是JPG-JPEG则给用户错误:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
alert('image has read completely!');
}
reader.readAsDataURL(input.files[0]);
}
}
Run Code Online (Sandbox Code Playgroud)