文件上传的动态添加输入项源代码
2011-11-26 19:33
447 查看
文件上传的动态添加输入项:
新建upload1.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>文件上传页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css"
href="styles.css">
-->
<script type="text/javascript">
function addfile(){
var files=document.getElementById("files");
<!--动态添加元素-->
var input=document.createElement("input");
input.name="file";
input.type="file";
var delButton=document.createElement("input");
delButton.type="button";
delButton.value="删除";
delButton.onclick=function del(){
<!--先删除父节点-->
this.parentNode.parentNode.removeChild(this.parentNode);
}
var div=document.createElement("div");
div.appendChild(input);<!--添加文件上传的输入项-->
div.appendChild(delButton);<!--添加删除按钮-->
<!--把div块添加到files div块中-->
files.appendChild(div);
}
</script>
</head>
<body>
<form action="${pageContext.request.contextPath}/servlet/UploadServlet" method="post" enctype="multipart/form-data">
<table border="1" width="40%">
<tr>
<td>上传用户:</td><td><input type="text" name="user"></td>
</tr>
<tr>
<td></td>
<td><input type="button" value="添加文件" onClick="addfile()"/></td>
</tr>
<tr>
<td></td>
<td><div id="files"></div></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="上传文件"/>
</td>
</tr>
</table>
</form>
</body>
</html>
新建upload1.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>文件上传页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css"
href="styles.css">
-->
<script type="text/javascript">
function addfile(){
var files=document.getElementById("files");
<!--动态添加元素-->
var input=document.createElement("input");
input.name="file";
input.type="file";
var delButton=document.createElement("input");
delButton.type="button";
delButton.value="删除";
delButton.onclick=function del(){
<!--先删除父节点-->
this.parentNode.parentNode.removeChild(this.parentNode);
}
var div=document.createElement("div");
div.appendChild(input);<!--添加文件上传的输入项-->
div.appendChild(delButton);<!--添加删除按钮-->
<!--把div块添加到files div块中-->
files.appendChild(div);
}
</script>
</head>
<body>
<form action="${pageContext.request.contextPath}/servlet/UploadServlet" method="post" enctype="multipart/form-data">
<table border="1" width="40%">
<tr>
<td>上传用户:</td><td><input type="text" name="user"></td>
</tr>
<tr>
<td></td>
<td><input type="button" value="添加文件" onClick="addfile()"/></td>
</tr>
<tr>
<td></td>
<td><div id="files"></div></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="上传文件"/>
</td>
</tr>
</table>
</form>
</body>
</html>
相关文章推荐
- JS动态添加文件上传组件 struts2
- ASP.NET(C#)实现一次性动态上传多张图片的代码(多个文件)
- asp.net后台代码动态添加JS文件和css文件的引用
- 创建动态添加上传文件页面
- Struts实现多个文件上传(动态添加数量、前台仿163邮箱)
- javaweb 简单的文件上传动态添加上传文件数量[从学习到工作(六)]
- 文件上传的动态添加输入项
- js动态添加文件上传框
- File Input多次添加文件,动态删除文件,用来实现上传等操作
- ASP.NET(C#)实现一次性动态上传多张图片的代码(多个文件)
- ajaxFileUpload+struts2实现多文件上传(动态添加文件上传框)
- Plupload上传文件动态添加页面参数
- 关于Html动态添加上传文件控件inputFile(附件)及清除已选择的文件的几个方法
- 利用javascript向网页中动态添加文件上传框
- ajaxFileUpload+struts2实现多文件上传(动态添加文件上传框)
- asp.net后台代码动态引用添加JS和css文件
- ASP.NET(C#)实现一次性动态上传多张图片的代码(多个文件)
- 实现动态的文件上传操作按钮的添加和删除
- js jquery分别实现动态的文件上传操作按钮的添加和删除
- ajaxFileUpload+struts2实现多文件上传(动态添加文件上传框)