input file 样式以及获取选择文件方法集合
样式一(http://www.cnblogs.com/jason-liu-blogs/archive/2013/06/13/3133377.html)
<style>
a{display:inline-block; width:100px; height:40px; background:red; position:relative; overflow:hidden;}
a:hover{background:green;}
input{position:absolute; right:; top:; font-size:100px; opacity:; filter:alpha(opacity=);}
</style> <a href="#">
<input type="file" value="浏览" />
</a>
外观一

样式二(http://www.jb51.net/css/69093.html)
CSS 代码
*{margin:;padding:;}
a{text-decoration:none;}
.btn_addPic{
display: block;
position: relative;
width: 140px;
height: 39px;
overflow: hidden;
border: 1px solid #EBEBEB;
background: none repeat scroll #F3F3F3;
color: #;
cursor: pointer;
text-align: center;
}
.btn_addPic span{display: block;line-height: 39px;}
.btn_addPic em {
background:url(http://p7.qhimg.com/t014ce592c1a0b2d489.png) 0 0;
display: inline-block;
width: 18px;
height: 18px;
overflow: hidden;
margin: 10px 5px 10px ;
line-height: 20em;
vertical-align: middle;
}
.btn_addPic:hover em{background-position:-19px ;}
.filePrew {
display: block;
position: absolute;
top: ;
left: ;
width: 140px;
height: 39px;
font-size: 100px; /* 增大不同浏览器的可点击区域 */
opacity: ; /* 实现的关键点 */
filter:alpha(opacity=);/* 兼容IE */
} HTML代码
<A class=btn_addPic href="javascript:void(0);"><SPAN><EM>+</EM>添加图片</SPAN> <INPUT class=filePrew title=支持jpg、jpeg、gif、png格式,文件小于5M tabIndex= type=file size= name=pic></A>
外观二

样式三(http://www.360doc.com/content/12/1229/13/11395036_256962485.shtml)
HTml 代码 <div class="fileInputContainer">
<input type="file" name="fileData" id="imgFlie" onchange="showPicture(this.files)" multiple />
</div> CSS代码
.fileInputContainer {
height: 80px;
background: url(http://wx115.cnpsim.com/Content/images/imagefile.png);
background-size: contain;
position: relative;
width: 80px;
text-align:center;
}
#imgFlie {
height: 80px;
overflow: hidden;
font-size: 100px;
position: absolute;
right: ;
top: ;
opacity: ;
filter: alpha(opacity=);
cursor: pointer;
}
样式三

*可以通过JQ注册change事件以便获取选择的文件或图片,在chang事件里面通过 this.files获取选择的文件等,也可像样式三代码中一样通过JS中onchange事件获取,
*有时text-align:center,并不能使其居中时可以尝试用margin-left:30%;margin-right:30%;
$("#imgFlie").live("change", function () {
var data = this.files;
//var data = document.getElementById('imgFlie').files;js获取
$(this).clone().replaceAll(file = this); //每次选中都保存旧元素,并使用新的控件替换(解决紧邻的二次不能选择同一图片)
$.each(data, function (key, value) {
var objUrl = getObjectURL(value);
if (objUrl) {
var img = new Image();
img.src = objUrl;
img.onload = function () {
var size = img.width + 'x' + img.height;
$("#ImageDiv").append('<figure><div>' +
'<a href=' +
'"' + objUrl + '"' +
'data-size=' +
'"' + size + '"' +
'>' +
'<img class="WorkOrderimageNew" style="height:90px;width:90px;" src=' +
'"' + img.src + '"' +
'>' +
'</a>' +
'</div>' +
'<figcaption style="display:none;">' +
'图片' +
//'<button style="float:right;" onclick=DeleteImage("' + value + '"' +
//',' +
//'"' + value + '")>删除图片(手机端需要注册触摸事件)</button> ' +
'</figcaption></figure>'
)
};
}
});
});
function showPicture(files) {
// var files = document.getElementById('imgFlie').files;
for (var i = ; i < files.length; i++) {
var file = files[i];
if (!/image\/\w+/.test(file.type)) {
return false;
}
var url = getObjectURL(file)
if (url) {
var img = new Image();
img.src = url;
img.onload = function () {
var size = img.width + 'x' + img.height;
$("#ImageDiv").append('<figure><div>' +
'<a href=' +
'"' + img.src + '"' +
'data-size=' +
'"' + size + '"' +
'>' +
'<img class="WorkOrderimageNew" style="height:40px;width:40px;" src=' +
'"' + img.src + '"' +
'>' +
'</a>' +
'</div>' +
'<figcaption style="display:none;">' +
'这是的图片名' +
'"' + file.name + '"' +
'</figcaption></figure>'
)
}
}
}
}
input file 样式以及获取选择文件方法集合的更多相关文章
- input file弹出框选择文件后缀限制
在页面选择文件时的弹出框默认显示的是所有类型的文件,有时候文件太多不好选择,我们就要过滤掉不想展示的文件,这是需要用到input的accept属性,只有在type="file"才有 ...
- IE input file隐藏不能上传文件解决方法
当大神们都在探讨更深层次的问题时,我还在这里转载发些肤浅的问题解决方案.罢了,为了和我一样笨的后来人. 问题: 上传文件时,用<input type="file" /> ...
- input file样式修改,图片预览删除功能
本篇对input file进行了修改,改成自己需要的样式,类似验证身份上传身份证图片的功能. 效果图如下: 这里主要展示上传预览图片功能,对于删除功能的html及css写的比较粗糙,对于想要精细表现这 ...
- 自定义input file样式
自定义input file样式:一般都是通过隐藏input,通过定义label来实现.这种做法要注意的是label的for属性要指定input对应的id; <!DOCTYPE html> ...
- input:file样式怎样修改
问题描述: 我需要点击input:file来修改img中的图片,但是input:file样式太丑 解决办法: 给file设置透明度为0,让用户看不见他 创建新的button按钮 修改button按钮样 ...
- input(file)样式修改及上传文件名显示
实现思路: a标签包裹input元素 设置a标签为上传按钮的样式,相对定位 设置input为透明,绝对定位,覆盖到a上面 效果:看到的按钮是a的样式,点击时实际是点击input元素.样式和功能都具备 ...
- 安装coreseek cannot find input file: src/Makefile.in 错误解决方法
安装coreseek 出现了cannot find input file: src/Makefile.in 解决方法如下 >autoheader >automake --add-missi ...
- input:file onchange事件无法读取解决方法
最近做项目,移动端的多文件上传,使用input:file读取文件 <input type='file' name='file' multiple accept='image/*' capture ...
- input file 无法打开手机端文件选择器
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/m0_37805167/article/details/78538044手机端对input file的 ...
随机推荐
- hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用
字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...
- sql 随机数
select FLOOR(rand()*16) 就是随机得到0到15之间的一个整数 select CEILING(rand()*15) 就是随机得到1到15之间的一个整数 FLOOR()为地板函数,取 ...
- 在EasyUI中统一判断是否有选中行,如果有则将选中行数据传入回调函数
function procossWithSeletedData(func) { var rowData = $("#tbGrid").datagrid("getSelec ...
- android一些常用的代码1(收藏)
以下内容来自多个开源项目的整理和自己的项目积累. 1.拨打电话 public static void call(Context context, String phoneNumber) { conte ...
- 基于vue2.0的一个分页组件
分页组件在项目中经常要用到之前一直都是在网上找些jq的控件来用(逃..),最近几个项目用上vue了项目又刚好需要一个分页的功能.于是百度发现几篇文章介绍的实在方式有点复杂, 没耐心看自己动手造轮子写了 ...
- MySQL忘记了密码登录不进去,用命令符修改新的密码重新登录的方法
MySQL忘记了密码登录不进去,用命令符修改新的密码重新登录的方法: 1.备份my.ini 2.在my.ini字段里 [mysqld] #socket=mysql skip-grant-tables ...
- Android 真机调试显示offline
今天调试程序部署的时候显示设备状态时offline. 然后突然想起来我通过命令行操作过设备. 然后找来一下,如下命令. adb kill-server adb devices
- Python 装饰器学习以及实际使用场景实践
前言 前几天在看Flask框架,对于非常神奇的@语法,不是非常的理解,回来补装饰器的功课.阅读很多的关于装饰器的文章,自己整理一下,适合自己的思路的方法和例子,与大家分享. app = Flask(_ ...
- Oracle EBS-SQL (BOM-15):检查多层BOM(含common BOM).sql
select distinct b.lvl 层次, b.OPERATION_SEQ ...
- 如何诊断crs 安装时 root.sh 脚本执行错误
troubleshooting root.sh problem ------*for 10g and 11.1 1.查证公网,私网的节点名是可以互相ping通的 2.---查证OCR/Voting 文 ...