dongzhan2461 2013-11-26 06:17
浏览 37

如何预览宽500px的图像。 只要 ? , 我能怎么做?

..........................................................................................

Why image still preview when image not width 500 px. , How can i do ?

..........................................................................................

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<?PHP // start script for preview image before upload // ?>
<script language="JavaScript">
    function showPreview_1(ele)
    {
            $('#imgAvatar_1').attr('src', ele.value); // for IE
            if (ele.files && ele.files[0]) {

                var reader = new FileReader();              
                reader.onload = function (e) {
                    $('#imgAvatar_1').attr('src', e.target.result);
                }
                reader.readAsDataURL(ele.files[0]);
            }
    }
</script>
<?PHP // end script for preview image before upload // ?>


Thumbnail image : 
<img id="imgAvatar_1" style=" max-height: 100px; max-width: 100px; border: 1px solid #ccc;" >
<input name="offer_image_1" type="file" id="offer_image_1" OnChange="showPreview_1(this)" />





<?PHP // start script for check wide image before upload // ?>
<script type="text/javascript">
var _URL = window.URL || window.webkitURL;
$("#offer_image_1").change(function(e) {
    var offer_image_1, img;
    if ((offer_image_1 = this.files[0])) {
        img = new Image();
        img.onload = function() {
            if (this.width != '500')
            {
            alert("not width 500 px.");
            $('input').val("");
            }
        };
        img.src = _URL.createObjectURL(offer_image_1);
    }
});
</script>
<?PHP // end script for check wide image before upload // ?>
  • 写回答

1条回答 默认 最新

  • donglianglu8136 2013-11-26 06:25
    关注

    Put

    img.src = _URL.createObjectURL(offer_image_1);
    

    line in else part for

    if (this.width != '500')
    {
        alert("not width 500 px.");
        $('input').val("");
    }
    

    It is being shown because you are setting the image source no matter whatever the width is. Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答