• 动态添加input标签


    <style type="text/css">
            .delete_attach
            {
                padding-left: 18px;
                background: url(../image/delete.png) no-repeat left top;
                margin-left: 7px;
                90px;
                color: #002f76;
            }
            .add_attach
            {
                padding-left: 22px;
                background: url(../image/add.png) no-repeat left center;
                90px;
                color: #002f76;
            }
        </style>
        <script type="text/javascript">
            var MAXFILES = 10;        //文件计数器
            var fileCount = 0;
            function addAttach(noAlert) {
                if (fileCount >= MAXFILES && !noAlert) { alert("最多只能添加" + MAXFILES + "个附件!"); return; }
                var fileSectionDiv = document.getElementById("files");
                var fileItemDiv = document.createElement("div");
                fileCount++;
                var content = "<input type='file' onchange='return addAttach(true);' id=='fileUpload'" + fileCount + " name='fileUpload'" + fileCount + ">&nbsp;<a href='#' onclick='return delAttach("" + fileCount + "")' class='delete_attach' >移除附件</a>";
                fileItemDiv.id = "fileItemDiv" + fileCount;
                fileItemDiv.innerHTML = content;
                fileSectionDiv.appendChild(fileItemDiv);
                return false;
            }

            function delAttach(fileIndex) {
                var fileSectionDiv = document.getElementById("files");
                var fileItemDiv = document.getElementById("fileItemDiv" + fileIndex);
                fileSectionDiv.removeChild(fileItemDiv);
                fileCount--;
                return false;
            }   
        </script>

    <form id="form1" runat="server" method="post" enctype="multipart/form-data">

    <a id="addAttach_a" onclick="return addAttach(false);" href="#" class="add_attach">添加附件</a>
                                <div id="files" runat="server">
                                </div>

    </form>

    string file = "Files";
                string path = Server.MapPath(file);
                if (!System.IO.Directory.Exists(path))//判断文件夹是否已经存在
                {
                    System.IO.Directory.CreateDirectory(path);//创建文件夹
                }
                for (int index = 0; index < Request.Files.Count; index++)
                {
                    if (!string.IsNullOrEmpty(Request.Files[index].FileName))
                    {
                        string NewName = DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(10000, 99999);
                        string Extension = Path.GetExtension(Request.Files[index].FileName);
                        Request.Files[index].SaveAs(Path.Combine(path, NewName + Extension));
                        details.Add(new AdvertiseDetail
                        {
                            Id = Utils.CreateGUID(),
                            FileName = file,
                            NewName = NewName + Extension,
                            OldName = System.IO.Path.GetFileName(Request.Files[index].FileName),
                            CreatedByID = "1001",
                            CreatedDate = DateTime.Now,
                            LastModifiedByID = "1001",
                            LastModifiedDate = DateTime.Now
                        });
                    }
                } 

     学习视频分享交流群

  • 相关阅读:
    【转载】Sqlserver存储过程中使用Select和Set给变量赋值
    【转载】腾讯云如何将一个域名解析到另一个域名上
    【转载】Sqlserver限制最大可使用内存
    【转载】 腾讯云通过设置安全组禁止某些IP访问你的服务器
    【转载】 C#使用Select方法快速获取List集合集合中某个属性的所有值集合
    【转载】哪些域名后缀可在工信部进行备案操作
    【转载】 C#使用string.Join快速用特定字符串串联起数组
    【转载】Sqlserver使用Convert函数进行数据类型转换
    【转载】Sqlserver根据生日计算年龄
    【转载】 腾讯云硬盘不够用,如何对硬盘进行扩容
  • 原文地址:https://www.cnblogs.com/hsliuyl/p/3954244.html
Copyright © 2020-2023  润新知