码迷,mamicode.com
首页 > Web开发 > 详细

图片上传压缩

时间:2015-05-21 10:29:37      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

<script type="text/javascript">
    var img = {
        Imgsource: [],
    }
    $(function () {
        $(".addimg").click(function () {
            $("#uploadFile").click();
        });
        $(‘#uploadFile‘).localResizeIMG({
            //width: 100,
            quality: 0.7,
            success: function (result) {
                //var img = new Image();
                //img.src = result.base64;
                showXY(result.base64);
                // $(‘body‘).append(img);
                // console.log(result);
            }
        });

        //$("#uploadFile").change(function () {
        //    var file = this.files[0];
        //    if (window.FileReader) {
        //        var reader = new FileReader();
        //        reader.readAsDataURL(file);
        //        //监听文件读取结束后事件
        //        reader.onloadend = function (e) {
        //            showXY(e.target.result, file.fileName);
        //        };
        //    }
        //});
        $("#<%=top.ClientID%>_Person").click(function () {
            var title = $("#title").val();
            var content = $("#content").val();
            if (title.length > 0 && content.length > 0) {
                $.ajax({
                    //要用post方式   
                    type: "Post",
                    //方法所在页面和方法名   
                    url: "TripAdd.aspx",
                    data: { act: "add", Img: img.Imgsource, title: title, content: content, id: ‘<%=TripId%>‘ },
                    dataType: "json",
                    success: function (data) {
                        //提交成功   
                        if (data.isSuc == "1") {
                            window.location = ‘TripList.aspx‘;
                        }
                    },
                });
            }
        });
    });
    function showXY(source) {
        $(".addimg").before(" <li class=\"cbox\"><img src=\"" + source + "\" alt=\"\"></li>");
        img.Imgsource.push(source.substr(source.indexOf(‘,‘) + 1));
    }
</script>

 

图片上传压缩

标签:

原文地址:http://www.cnblogs.com/hausthy/p/4518822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!