图像预览不显示

时间:2019-02-12 06:06:59

标签: ajax preview

当问题文件更改时我需要,然后预览将显示在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 [图像容器]中不显示任何内容

0 个答案:

没有答案
相关问题