zoukankan      html  css  js  c++  java
  • asp.net无刷新上传(带预览)

    1.有个图片

    <img id="Image1" title="用于广告栏及图文框缩略图" width="150" height="100" />

    2.存储路径

     <asp:HiddenField ID="HiddenField_Image1" runat="server" />

    3.初始化js

    <script type="text/javascript" src="Scirpt/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="Scirpt/ajaxupload.js"></script>

    $(function () {
    var hidimg = document.getElementById("HiddenField_Image1");
    var btnImg = document.getElementById("Image1");
    uploadFile(btnImg, hidimg);
    });

    4.上传代码

    function uploadFile(btn, hidimg) {
    var button = btn;
    new AjaxUpload(button, {
    action: 'TTHandler.ashx',
    data: {},
    name: 'myfile',
    onSubmit: function (file, ext) {
    if (!(ext && /^(jpg|JPG|png|PNG|gif|GIF)$/.test(ext))) {
    alert("您上传的图片格式不对,请重新选择!");
    return false;
    }
    },
    // 开始上传文件
    onSubmit: function (file, extension) {
    $("#state").val("正在上传" + file + "..");
    },
    // 上传完成之后
    onComplete: function (file, result) {
    var remsg = result.split("|");
    var name = remsg[1].split("/");
    if (remsg[0] == "1") {
    $(btn).attr("src", remsg[1]);
    $(hidimg).val(remsg[1]);
    $("#state").val("上传成功..");
    } else {
    $.messager.alert("提示", remsg[2]);
    }
    }
    });
    }

    完整下载路径

    http://download.csdn.net/detail/jine515073/9436752

     

  • 相关阅读:
    字典
    字符串常用的方法
    切片,集合、文件处理
    蓝桥杯练习 Day6 题解
    spoj-ORDERS
    spoj-SUBSUMS
    spoj
    spoj --- ABCDEF
    C. Andryusha and Colored Balloons
    B. The Meeting Place Cannot Be Changed
  • 原文地址:https://www.cnblogs.com/linyijia/p/5201281.html
Copyright © 2011-2022 走看看