动态添加input标签
<style type="text/css">
.delete_attach
{
padding-left: 18px;
background: url(../image/delete.png) no-repeat left top;
margin-left: 7px;
width: 90px;
color: #002f76;
}
.add_attach
{
padding-left: 22px;
background: url(../image/add.png) no-repeat left center;
width: 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 + "> <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
});
}
}
动态添加input标签的更多相关文章
- easyui 动态添加input标签
动态添加easyui控件<input class=" easyui-textbox" > 这样是无效的,因为easyui没有实时监控,所以必须动态渲染$.parser. ...
- js获取不到动态添加的标签的值的解决方法
遇到了js无法获得动态添加的标签的值,百度了一番,最后自己解决了问题,但是原理现在还不怎么明确. $("input[id='txtAttValue']").each(functio ...
- ThinkPHP框架下,给jq动态添加的标签添加点击事件移除标签
jq移除标签主要就是$("#要移除的id").remove();不再赘述,这里要提醒的是jq中动态添加标签后怎样添加点击事件.一般的jq添加点击事件是用这种方法$("#i ...
- jQuery动态添加li标签并添加属性和绑定事件
代码如下: <%@page import="java.util.ArrayList"%> <%@ page language="java" c ...
- js JQ动态添加div标签
function renderList(data){ var str = ''; for(var i = 0; i < data.length; i++){ // 动态添加li str += ' ...
- JS从后台获取数据,前台动态添加tr标签中的td标签
功能描述: 要求从后台查询该省份的所有城市,然后动态的再前台固定的tr标签中添加相应的td标签来展示城市基本信息: 文章目录 #一.前台jsp及js源码 jsp:在固定的tr标签中添加一个id,通过j ...
- MyBatis动态添加—trim标签
做添加时,部分字段有值,没值的字段不添加,这就是动态添加,使用 trim 标签就可以实现. <insert id="insertSysUser" parameterType= ...
- JS动态添加的标签无法绑定事件解决方案~~~
今天用ajax实现动态插入数据时发现监听一直不起作用,一样的代码,非动态的就可以监听实现 这是困扰了我近一个小时的bug,后面才理解到可能是动态插入导致的! 看了看网上的解决方案,似乎都不太通俗,讲的 ...
- 利用jQuery动态添加input输入框,并且获取他的值
动态添加 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco ...
随机推荐
- js运动框架之掉落的扑克牌(重心、弹起效果)
玩过电脑自带纸牌游戏的同志们应该都知道,游戏过关后扑克牌会依次从上空掉落,落下后又弹起,直至"滚出"屏幕. 效果如图: 这个案例的具体效果就是:点击开始运动,纸牌会从右上角掉 ...
- 三种Singleton的实现方式
来源:http://melin.iteye.com/blog/838258 三种Singleton的实现方式,一种是用大家熟悉的DCL,另外两种使用cas特性来实现. public class Laz ...
- javascript中日期格式与时间戳之间的转化
日期格式与时间戳之间的转化 一:日期格式转化为时间戳 function timeTodate(date) { var new_str = date.replace(/:/g,'-'); new_str ...
- Json序列化,date类型转换后前端显示错误的解决方案
1.前台使用Jquery解决 (1)如果我们前台使用Jquery来解决这个问题的话,那么我们首先想到的是我们如何解析这个过程呢,当然我们就想到了自己写一个JavaScript脚本来解析这个过程,当然这 ...
- deep learning 练习 牛顿法完成逻辑回归
Logistic Regression and Newton's Method 作业链接:http://openclassroom.stanford.edu/MainFolder/DocumentPa ...
- 利用微软AntiXss Library过滤输出字符,防止XSS攻击
假如项目在前期没有过滤客户提交的字符,那么可以在输出的时候,对输出的字符进行过滤,防止出现XSS跨域攻击. 原理简单:利用ASP.NET API的管道原理,在MessageHandlers中添加一个自 ...
- SQL Server安全概念简析
I. 登录名与用户名 登录名: 访问数据库服务器的账户.登录名可以登录到服务器,但不能直接访问数据库内容.数据库连接串中的用户名应配置为登录名.每个登录名的定义存放在master数据库的syslogi ...
- linux中mysql如何设置为开机启动
开机启动命令 chkconfig mysqld on 查询是否设置为开机启动命令 chkconfig --list mysqld 结果为 mysqld 0:关闭 1:关闭 2:启动 3:启动 4:启动 ...
- java中interface的详解
JAVA的核心概念:接口(interface) 接口与类属于同一层次,实际上,接口是一种特殊的抽象类. 如: interface IA{ } public interface: 公开接口 与 ...
- 哈夫曼树---POJ3253
http://poj.org/problem?id=3253 这就是 最典型的哈夫曼树的题型,我们就根据这道题学习一下哈夫曼树 这是最开始我们把21据下来之后我们据下8,然后再据下5得到34,可以看出 ...