非IE图片上传预览

 $("#uploadFiles").change(function (e) {
                if (e.target.files) {
                    var files = e.target.files || e.dataTransfer.files;
                    for (var i = 0; i < files.length; i++) {
                        Output("<div><strong>" + files[i].name + "</strong></div>");
                    }
                } else {
                    var fileValArray = $(this).val().split("\\");
                    var fileVal = fileValArray[fileValArray.length - 1];
                    Output("<div><strong>" + fileVal + "</strong></div>");
                }
                //                if (e.target.files) {
                //                    var files = e.target.files || e.dataTransfer.files;
                //                    for (var i = 0; i < files.length; i++) {
                //                        ParseFile(files[i]);
                //                    }
                //                } else {
                //                    var fileValArray = $(this).val().split("\\");
                //                    var fileVal = fileValArray[fileValArray.length - 1];
                //                    Output("<div><strong>" + fileVal + "</strong></div>");
                //                }
            });
        });

 

 

/*  非IE浏览器    */
        function Output(msg) {
            var m = $("#showHTML").html();
            $("#showHTML").html(msg + m);
        }
        var FileStr = "";
        function ParseFile(file) {
            var reader = new FileReader();
            reader.onload = function (e) {
                Output(
                /* "<p><strong>" + file.name + ":</strong><br />"
                +'<img src="' + e.target.result + '" /></p>' */
                "<div><strong>" + file.name + "</strong></div>"
    );
                FileStr = e.target.result;
            }
            reader.readAsDataURL(file);
        }
        /*  非IE浏览器    */

posted @ 2013-10-30 10:59  xyzhuzhou  阅读(185)  评论(0编辑  收藏  举报