动态添加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 ...
随机推荐
- R语言-实用数据对象处理函数
length(object) 显示对象中元素/成分的数量 dim(object) 显示某个对象的维度 str(object) 显示某个对象的结构 class(object) 显示某个对象的类或类型 m ...
- MySql自增长列
1. 关键字 auto_increment 2. 自增用法 a) create table test(tid int auto_increment, tname varchar(10), primar ...
- 利用Continuous Testing实现Eclipse环境自动单元测试
当你Eclipse环境中修改项目中的某个方法时,你可能由于各种原因没有运行单元测试,结果代码提交,悲剧就可能随之而来. 所幸infinitest(http://infinitest.github.io ...
- [转]Amazon DynamoDB – a Fast and Scalable NoSQL Database Service Designed for Internet Scale Applications
This article is from blog of Amazon CTO Werner Vogels. -------------------- Today is a very exciting ...
- 华硕Z97-A主板声卡设置
$ vim /usr/share/alsa/alsa.conf ## defaults# # show all name hints also for definitions without hint ...
- 关于Oracle出现listener refused the connection with the ORA-12505错误,解决方案
出现listener refused the connection with the ORA-12505错误,解决方案: 1.首先重启一下电脑,释放被占用的1521端口 2.重启后打开Oracle D ...
- selenium 介绍1
本文主要是吸收这些帖子的营养,多谢互联网,和未知名作者. http://www.ltesting.net/ceshi/open/kygncsgj/selenium/2011/1009/203318.h ...
- Python-0 简述
#1 应用广泛: 豆瓣 youtube 云存储相关 #2 初步学习内容:
- ant批量执行Jmeter脚本
JDK,Jmeter默认已经装了 ANT下载:http://ant.apache.org/bindownload.cgi ant环境变量需要配置 ant_home,你解压之后的地址 然后PATH环境变 ...
- OCP认证之Oracle的SQL语言基础(一)
一.Oracle命令类别 数据操纵语言(DML):select;insert;delete;update;merge 数据定义语言(DDL):create;alter;drop;truncate 事物 ...