在Mozilla上生成图像预览?

时间:2012-11-07 05:30:05

标签: javascript jquery html

我编写了代码来获取图像文件并生成上传图像的预览。 当我读取图像文件数据并生成预览时,它不显示图像的预览,但是当我在绑定图像源之前设置警报时,这是正确的。

我该如何解决这个问题?

以下是代码段

function changeSrc(file) {

            var reader = new FileReader();

            // array with acceptable file types
            var accept = ["image/png", "image/jpeg", "image/jpg", "image/gif"];

            // if we accept the first selected file type
            if (accept.indexOf(file.files[0].type)> -1) {
                if (file.files && file.files[0]) {
                    reader.readAsDataURL(file.files[0]);

                   If i remove this alert then preview creates problem
                   --> ***alert(reader.result);***

                    $(#previewField).attr(src, reader.result);

                }
            }
    }

0 个答案:

没有答案
相关问题