1.表单上传文件的步骤:

- 1)设置enctype

默认为:enctype="application/x-www-form-urlencoded"(一般不设置)

若要表单中有需要上传文件的表单项时,则必须设置enctype:enctype="multipart/form-data"

- 2)设置method:提交方式

默认:get
需要上传文件时,必须设置为post

因为get方式携带的信息量太小,而且传输的数据都会显示在地址栏,对于图片等文件无法处理


2.上传文件

一次只能选择一个文件上传

伪代码

<form action="UploadOneServlet" method="post" name="f_upload" enctype="multipart/form-data">
<input type="text" name="username" /><br>
<input type="file" name="filename" /><br>
<input type="submit" value="上传" />
</form>

运行结果

此时我们可以看到一次只能选择一个文件,进行上传。


一次能同时选中多个文件同时上传

很多时候我们需要同时选择多个文件实现多个文件的上传,那么只选择一个文件的情况就不适用,如何设置呢?

在input中设置属性multiple即可 - - multiple=”multiple”

伪代码

<form action="UploadOneServlet" method="post" name="f_upload" enctype="multipart/form-data">
<input type="text" name="username" /><br>
<input type="file" name="filename" multiple="multiple" /><br>
<input type="submit" value="上传" />
</form>

运行结果

此时我们可以看到一次可以选择多个文件,进行上传。

css input[type=file] 样式美化(input上传文件样式 )

效果:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
/*样式1*/
.a-upload {
padding: 4px 10px;
height: 20px;
line-height: 20px;
position: relative;
cursor: pointer;
color: #888;
background: #fafafa;
border: 1px solid #ddd;
border-radius: 4px;
overflow: hidden;
display: inline-block;
*display: inline;
*zoom: 1
} .a-upload input {
position: absolute;
font-size: 100px;
right: 0;
top: 0;
opacity: 0;
filter: alpha(opacity=0);
cursor: pointer
} .a-upload:hover {
color: #444;
background: #eee;
border-color: #ccc;
text-decoration: none
}
/*样式2*/
.file {
position: relative;
display: inline-block;
background: #D0EEFF;
border: 1px solid #99D3F5;
border-radius: 4px;
padding: 4px 12px;
overflow: hidden;
color: #1E88C7;
text-decoration: none;
text-indent: 0;
line-height: 20px;
}
.file input {
position: absolute;
font-size: 100px;
right: 0;
top: 0;
opacity: 0;
}
.file:hover {
background: #AADFFD;
border-color: #78C3F3;
color: #004974;
text-decoration: none;
}
</style>
</head>
<body style="padding: 10px">
<a href="javascript:;" class="a-upload">
<input type="file" name="" id="">点击这里上传文件
</a>
<a href="javascript:;" class="file">选择文件
<input type="file" name="" id="">
</a>
</body>
</html>

带有图片预览功能的上传表单

http://blog.csdn.net/haibo0668/article/details/77262452

引用:http://blog.163.com/yibei_kukafei/blog/static/300210212015519114718389/

 

input 原生上传文件(type = file)的更多相关文章

  1. input 限制 上传文件类型

    参考:input file控件限制上传文件类型 HTML <input> 标签的 accept 属性 网页上添加一个input file HTML控件: <input id=&quo ...

  2. ASP.NET MVC使用input标签上传文件

    有些时间学习了,温习一下ASP.NET MVC了.上传文档是在开发过程中,必须撑握的一个功能.以前上传均是使用第三方控件uploadify来实现,今天使使用VS标准标签input 的type=&quo ...

  3. JS分段上传文件(File)并使用MD5.js加密文件段用来后台校验

    HTML <form method="POST" name="form1" action="/mupload/upload/" enc ...

  4. input如何上传文件

    1)绑定input[type='file']的change事件 <input @change="uploadPhoto($event)" type="file&qu ...

  5. android 模拟器上传文件 Read-only file system

    在cmd窗口一条命令就可以了:adb shellmount -o remount rw /

  6. Html标签,file方式,上传文件

    恩,如果不记下来,记忆就会模糊掉. 希望自己下次看见这篇博客的时候,会解决掉疑问 ----------------------------------------------------------- ...

  7. SpringMVC上传文件的三种方式(转)

    直接上代码吧,大伙一看便知 这时:commonsmultipartresolver 的源码,可以研究一下 http://www.verysource.com/code/2337329_1/common ...

  8. SpringMVC上传文件的三种方式

    直接上代码吧,大伙一看便知 这时:commonsmultipartresolver 的源码,可以研究一下 http://www.verysource.com/code/2337329_1/common ...

  9. springmvc+ajaxFileUpload上传文件(前后台彻底分离的情况下)

    首先是导入jar包: web.xml: <servlet> <servlet-name>mvc-dispatcher</servlet-name> <serv ...

随机推荐

  1. js版MD5 (Message-Digest Algorithm)加密算法

    /**** MD5 (Message-Digest Algorithm)* http://www.webtoolkit.info/***/ var MD5 = function (string) { ...

  2. 二:Recovery models(恢复模式)

    For each database that you create in SQL Server, with the exception of the system databases, you can ...

  3. 吴裕雄 python 机器学习-NBYS(1)

    import numpy as np def loadDataSet(): postingList=[['my', 'dog', 'has', 'flea', 'problems', 'help', ...

  4. 前往央都之行-gdufe1529

    前往央都之行 Time Limit: 2000/1000ms (Java/Others) Problem Description: 刀光哥桐人和尤吉欧两人为了拯救爱丽丝,同时从卢利特村出发要尽快同时赶 ...

  5. ubuntu下安装nodejs和npm

    第一种安装方法: 安装nodejs : 1 sudo apt-get install nodejs 运行 nodejs -v 会弹出安装node的版本号 这里使用的是 nodejs 并不是常用的nod ...

  6. VSC KeyNote

    [VSC KeyNote] 1.前后跳转. Alt + LeftArrow, Alt + RightArrow 2.缩进问题. vsc默认缩进为4,但js代码里缩进依旧是2. 因为vscode默认启用 ...

  7. JMeter学习(四)参数化(转载)

    转载自 http://www.cnblogs.com/yangxia-test JMeter也有像LR中的参数化,本篇就来介绍下JMeter的参数化如何去实现. 参数化:录制脚本中有登录操作,需要输入 ...

  8. 【pyspider】启动爬虫后在results页面没有看到结果

    今天根据书上的介绍写了一个简单爬虫,爬取豌豆荚里面APP的基本信息,但是在调试结果正常后,发现跳转到result页面后没有看到结果. 后来上网查了一下,发现要在def detail_page(self ...

  9. IDEA错误:Cannot start compilation: the output path is not specified for module "Test". Specify the out

    错误是发生在从github上checkout自己的项目时.因为没有将配置文件一起上传,所以在运行Java程序时有了这个报错: Cannot start compilation: the output ...

  10. 反射实现 AOP 动态代理模式(Spring AOP 的实现原理)

    枚举 在某些情况下,一个类的对象是有限而且固定的,比如季节类,它只有4个对象.这种实例有限而且固定的类,在Java里被称为枚举类. 枚举就是要让某个类型的变量的取值只能为若干个固定值中的一个,否则,编 ...