zoukankan      html  css  js  c++  java
  • MVC上传图片

    <td rowspan="8"> 图片为:
    <input type="hidden" name="img_url" id="img_url" value="@Model.img_url"/>
    <img id="img_head1" style="height:200px; 300px; @(Model.img_url == "" ? "display:none;" : "")" src="@(AppSettingGetValue.getFileServices() + "platformContent/TuWen/" + Model.img_url)"/><br />
    <input type="file" name="fileImgUrl" id="fileToUpload1" multiple="multiple" onchange="fileSelected(1);" />
    <a id="uploadFile1" style="display: none" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="uploadFile(1)">上传</a>
    </td>

    JQuery控制图片上传

    function fileSelected(itype) {
    $("#uploadFile" + itype).show();
    }

    var uploadtype = 0;
    function uploadFile(itype) {
    uploadtype = itype;
    var fd = new FormData();
    var xhr = new XMLHttpRequest();
    xhr.addEventListener("load", uploadComplete, false);
    fd.append("fileToUpload", document.getElementById('fileToUpload' + itype).files[0]);
    if (itype == 0) fd.append("UpLoadAdress", "platformContent\TuWen\");
    else fd.append("UpLoadAdress", "platformContent\TuWen\");
    xhr.open("POST", "@Url.Content("~/Common/UploadFile")");
    xhr.send(fd);
    }

    function uploadComplete(evt) {

    /* 服务器返回数据 */
    var message = evt.target.responseText;
    if (uploadtype == 0) {
    $("#img_head").show();
    $("#img_head").attr("src", "@(BBAdmin.Common.AppSettingGetValue.getFileServices())platformContent/TuWen/" + message);

    if ($("#fileToUpload" + uploadtype).val() == "") {
    $.message.alert("提示", "二维码上传成功!", "info");
    }
    else {
    $("#fileToUpload" + uploadtype).val("");
    }
    }
    if (uploadtype == 1) {
    $("#img_head1").show();
    $("#img_url").val(message);
    $("#img_head1").attr("src", "@(BBAdmin.Common.AppSettingGetValue.getFileServices())platformContent/TuWen/" + message);
    //$("#img_url").val($("#img_head1").attr("src"));

    if ($("#fileToUpload1" + uploadtype).val() == "") {
    $.messager.alert("提示", "头像上传成功!", "info");
    }
    else {
    $("#fileToUpload1" + uploadtype).val("");
    }
    }
    }

  • 相关阅读:
    ubuntu14.0 服务器webmin安装
    python如何简单的处理图片(1):打开显示
    如何在YouTube上下载视频
    Ubuntu下下载使用sublime
    IndentationError: unexpected indent
    Linux下vim显示行数
    Linux下tree的使用介绍
    Mac利用分屏spliter
    redis开机自启动脚本(linux)
    java 反射应用
  • 原文地址:https://www.cnblogs.com/zxk3113/p/4653493.html
Copyright © 2011-2022 走看看