$(document).ready(function() {
$('#StudentPhoto').change(function()
{
var file_data = $("#StudentPhoto").prop("files")[0];
var size = file_data.size;
var type = file_data.type;
var name = file_data.name;
var input = $("#StudentPhoto");
if(type !== 'image/png' && type !== 'image/jpg' && type !== 'image/jpeg')
{
alert("Only JPG & PNG files are allowed to upload as student photo.");
$('#StudentPhoto').click();
}
else if(size > 2097152)
{
alert("The maximum photo size is 2MB\n");
$('#StudentPhoto').click();
}
});
});
Если выбранный пользователем файл имеет недопустимый формат или размер, должно появиться диалоговое окно с просьбой снова выбрать файл, но этого не происходит, оператор $('#StudentPhoto').click(); в функции не работает. Почему? Есть ли другой метод?
[code]$(document).ready(function() { $('#StudentPhoto').change(function() { var file_data = $("#StudentPhoto").prop("files")[0]; var size = file_data.size; var type = file_data.type; var name = file_data.name; var input = $("#StudentPhoto");
if(type !== 'image/png' && type !== 'image/jpg' && type !== 'image/jpeg') { alert("Only JPG & PNG files are allowed to upload as student photo."); $('#StudentPhoto').click(); } else if(size > 2097152) { alert("The maximum photo size is 2MB\n"); $('#StudentPhoto').click(); } }); }); [/code]
Если выбранный пользователем файл имеет недопустимый формат или размер, должно появиться диалоговое окно с просьбой снова выбрать файл, но этого не происходит, оператор $('#StudentPhoto').click(); в функции не работает. Почему? Есть ли другой метод?