兼容IE6.0 7.0 8.0 FF上传预览

来源:互联网 发布:淘宝网怎么注册账户 编辑:程序博客网 时间:2024/06/10 01:33

兼容IE6.0 7.0 8.0 FF上传预览

 

<script type="text/javascript">
        function getPath(obj) {
            if (obj) {

                if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
                    obj.select();
                    $("img").remove("#img1");
                    document.getElementById('pic').filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = document.selection.createRange().text;

                }
                else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {

                    if (obj.files) {

                        $("#img1").attr("src", obj.files.item(0).getAsDataURL());
                    }
                }

            }
        }
    </script>

html代码

 <input type="file" onchange="getPath(this);" />
    <div id="pic" style="width: 100px; border: solid 1px red; height: 100px; filter:        progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);">
        <img id="img1" width="100px;" />
    </div>

原创粉丝点击