Мне нужно при изменении файла вопроса, тогда превью будет показываться в imgques
<input class="form-control" type="file" name="questionfile" id="questionfile"/>
<img class="form-control" id="imgques" style="height:210px ; width:510px;/>"
Функция:
$("#questionfile").change(function() {
var imgPath = $(this)[0].value;
var extn = imgPath.substring(imgPath.lastIndexOf('.') + 1).toLowerCase();
if (extn == "gif" || extn == "png" || extn == "jpg" || extn == "jpeg" || extn == "bmp") {
if (typeof (FileReader) != "undefined") {
var imgques = $("#imgques");
imgques.empty();
var reader = new FileReader();
reader.onload = function (e) {
$("<img />", {
"src": e.target.result,
"class": "thumb-image",
"height": "200px",
"width": "400px"
}).appendTo(imgques);
}
imgques.show();
reader.readAsDataURL($(this)[0].files[0]);
} else {
alert("This browser does not support FileReader.");
}
} else {
alert("Pls select only images");
}
});
, если я не выберу файл изображения, он будетпоказывать совершенное оповещение, но если я выберу какое-либо изображение, оно ничего не отобразит в img [контейнер изображения]