日期:2014-05-19  浏览次数:20696 次

关于JSP上传图片的预览问题。
以下是js:

JScript code

<script type="text/javascript">
    function checkPic() {
        alert("1111");
        var picPath = document.getElementById("picPath").value;
        alert("picPath is " + picPath);
        var type = picPath.substring(picPath.lastIndexOf(".") + 1,
                picPath.length).toLowerCase();

        if (type != "jpg" && type != "bmp" && type != "gif" && type != "png") {
            alert("error1");
            return false;
        }
        return true;
    }

    function PreviewImage(divImage, upload, width, height) {

        try {
            var imgPath;
            var Browser_Agent = navigator.userAgent;

            if (Browser_Agent.indexOf("Firefox") != -1) {
                imgPath = upload.file[0].getAsDataURL();
                document.getElementById(divImage).innerHTML = "__tag_48$49_"
            } else {
                var Preview = document.getElementById(divImage);
                alert(Preview);
                Preview.filters
                        .item("DXImageTransform.Microsoft.AlphaImageLoader").src = upload.value;
                Preview.style.width = width;
                Preview.style.height = height;
            }
        } catch (e) {
            alert(e);
        }

    }
</script>



以下是jsp
HTML code

<input type="file" id="picPath" name="doc" onchange="PreviewImage('Preview',this,120,120)">
<div id="Preview" style="filter: progid :DXImageTransform.Microsoft.AlphaImageLoader (sizingMethod = scale ;"></div>



选择文件之后 会走到一个异常
“e” cannot call method 'item' of undefined

怎么修改?

------解决方案--------------------
Preview.filters
.item("DXImageTransform.Microsoft.AlphaImageLoader").src = upload.value;
这个方法 ,不知道 js里有没有呢??
------解决方案--------------------
我有源码,如果需要,给你看下,不过要临时抽出来~!!!!!
类似于头像 预览的那种。