var nme = document.getElementById("uploadFile");
if(nme.value.length < 4) {
alert('Must Select any of your photo for upload!');
nme.focus();
return false;
}
function validateAndUpload(input){
var URL = window.URL || window.webkitURL;
var file = input.files[0];
if (file) {
var image = new Image();
image.onload = function() {
if (this.width) {
console.log('Image has width, I think it is real image');
//TODO: upload to backend
}
};
image.src = URL.createObjectURL(file);
}
};
<input type="file" name="uploadPicture" accept="image/*" onChange="validateAndUpload(this);"/>
var elements = document.getElementsByClassName('uploadFile_ClassName');
for (var i = 0; i < elements.length; ++i) {
if(elements[i].value != "") {
// file is selected here;
}
}
5条答案
按热度按时间0pizxfdo1#
这在IE(和FF,我相信)中是有效的:
mwecs4sa2#
ohfgkhjo3#
更改时调用此函数。
k97glaaz4#
您可以用途:
这三种给予的结果相同。
92dk7w1h5#
已接受的答案是否正确,以“ID”进行检查
但是,那些在这里检查文件的人有类名、
代码如下: