zoukankan      html  css  js  c++  java
  • JQuery之replace以及给控件赋值

    <input type="hidden" name="ImgUrl"  readonly="readonly">
    <input type="file" id="imgurl_uploadify" />
    <img id="imgurl_view" width="100" height="100"/>
    

     最上面的那个input是自己添加的,主要用于获取上传的图片的路径,然后传给name为ImgUrl的表单元素,从而在提交的时候将其值传递,下面的两个控件是uploadify上传图片控件要用的

    下面是jquery上传代码:

    @section scripts{
        <script type="text/javascript">
            $(function () {
                //上传图片
                $("#imgurl_uploadify").uploadify({
                    'queueSizeLimit': 1,	//上传的数量
                    'uploader': '/HttpHandler/UploadifyHandler.ashx',       //网站中的UploadifyHandler.ashx文件地址
                    'swf': '/Content/js/plugins/uploadify/uploadify.swf',   //该文件在项目中的位置
                    'onUploadSuccess': function (file, data, response) {    //这里的data是从UploadifyHandler.ashx文件获取过来的netPath
                        //下面的这句话是将上传的图片的url赋值给img控件的src属性
                        $('#imgurl_view').attr('src', data);
                        //这句话是将上传的图片的url赋值给input控件的value属性,从而提交表单的时候会获取到该name为ImgUrl的input控件的value值,这里的WebUrl是Http://localhost:2551
                        $("input[name='ImgUrl']").attr('value', data.replace('@System.Configuration.ConfigurationManager.AppSettings["WebUrl"]', ''));
                    },
                    'onQueueComplete': function () {
                    },
                    //检测FLASH失败调用
                    'onFallback': function () {
                        alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。");
                    },
                    //载入时触发,将flash设置到最小
                    'onInit': function () {
                        $(".uploadify-queue").hide();
                    }
                });
    
            })
        </script>
    }
    

     下面再看看图片上传时的路径:

    public void ProcessRequest(HttpContext context)
            {
                HttpPostedFile file = context.Request.Files["Filedata"];
    
    //带net的路径变量都是网络路径;带upload的路径变量都是本地服务器路径,即保存到本地的路径
    //WebUrl=http://localhost:2551,显示图片的时候是找此路径的 var netRoot = System.Configuration.ConfigurationManager.AppSettings["WebUrl"]; //WebPath=D:项目-----------公司--代码Linkin2Linkin.Web,是将其上传到Web项目中,如果不加这句的是默认保存到Manager里了 var uploadRoot = System.Configuration.ConfigurationManager.AppSettings["WebPath"]; var strogeFolder = "/Upload/Uploadify"; var netPath = string.Format("{1}/{0}/", DateTime.Now.ToString("yyyy/MM/dd"), strogeFolder); //下面这种写法是保存到linkin.Manager项目下的文件夹下了,但是现在要保存到Web下 //var uploadPath = HttpContext.Current.Server.MapPath(netPath); var uploadPath = string.Format("{0}/{1}/{2}/", uploadRoot, strogeFolder, DateTime.Now.ToString("yyyy/MM/dd")); if (file != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } var fileName = string.Format("{0}{1}", IDHelper.Id32, file.FileName.Substring(file.FileName.IndexOf('.'))); netPath = string.Format("{2}{0}{1}", netPath, fileName, netRoot); uploadPath = string.Format("{0}{1}", uploadPath, fileName); file.SaveAs(uploadPath); //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失 context.Response.Write(netPath); } else { context.Response.Write("0"); } }

                

  • 相关阅读:
    each和foreach的区别
    apply和call的用法
    js小知识点
    关于react的一些疑问点
    c语言字符动画的实现
    解决'chromedriver' executable needs to be in PATH问题!
    二叉树的创建和遍历
    dns和dhcp
    编写一个application程序实现如下功能:接受命令行中给出的一个字符串,先将字符串原样输出,然后判断该穿的第一个字母是否为大写,若是大写则统计该串中大写字母的个数,并将所有大写字母输出。
    学生成绩管理系统究极版
  • 原文地址:https://www.cnblogs.com/cocoon/p/4997021.html
Copyright © 2011-2022 走看看