html5读取本地文件示例代码
建站知识 2021-07-02 23:00www.168986.cn长沙网站建设
html结构样式如下
<div class="addpic">
<button>添加图片</button>
<form>
<input id="logoimg" class="addlogo" type="file" multiple aept="image/" name="logo">
</form>
</div>
<img id="showlogo" src="" alt="">
从样式上说应不显示input元素的输入框,这时需将input设置为透明样式,然后将其覆盖到button元素上方,这时方可实现点击button上传图片。将aepted设置为“image/”,则只允许图片类文件上传。
Css样式如下
.addpic{
position:relative;
margin-left:100px;
width:95px;
height:30px;
}
.addlogo {
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
cursor: pointer;
font-size: 30px;
opacity: 0;
position: absolute;
right: 0;
: 0;
z-index: 10;
}
js代码
function readFiles(evt){
var files=evt.target.files;
if(!files){
console.log("the file is invaild");
return;
}
for(var i=0, file; file=files[i]; i++){
var imgele=new Image();
var thesrc=window.URL.createObjectURL(file);
imgele.src=thesrc;
imgele.onload=function(){
$("#showlogo").attr("src",this.src);
}
}
}
$(document).ready(function(){
$("#logoimg").change(function(e){
readFiles(e)
});
});
复制代码
代码如下:<div class="addpic">
<button>添加图片</button>
<form>
<input id="logoimg" class="addlogo" type="file" multiple aept="image/" name="logo">
</form>
</div>
<img id="showlogo" src="" alt="">
从样式上说应不显示input元素的输入框,这时需将input设置为透明样式,然后将其覆盖到button元素上方,这时方可实现点击button上传图片。将aepted设置为“image/”,则只允许图片类文件上传。
Css样式如下
复制代码
代码如下:.addpic{
position:relative;
margin-left:100px;
width:95px;
height:30px;
}
.addlogo {
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
cursor: pointer;
font-size: 30px;
opacity: 0;
position: absolute;
right: 0;
: 0;
z-index: 10;
}
js代码
复制代码
代码如下:function readFiles(evt){
var files=evt.target.files;
if(!files){
console.log("the file is invaild");
return;
}
for(var i=0, file; file=files[i]; i++){
var imgele=new Image();
var thesrc=window.URL.createObjectURL(file);
imgele.src=thesrc;
imgele.onload=function(){
$("#showlogo").attr("src",this.src);
}
}
}
复制代码
代码如下:$(document).ready(function(){
$("#logoimg").change(function(e){
readFiles(e)
});
});
上一篇:html5菜单折纸效果
下一篇:使用html5制作loading图的示例
长沙网站设计
- 如何进行东阳SEO关键词优化?
- 边坝哪有关键词排名优化:提升你的网站流量与
- 安国百度优化服务:提升您的在线可见性
- 阜康新手做SEO怎么做
- 山西seo网站排名关键词优化:提升您网站曝光率
- 临沂seo网站排名关键词优化:提高你的网站可见
- 广西SEO网站推广怎样付费比较合理
- 双辽SEO网站推广:提升你的网站可见性与流量
- 辽宁企业网站优化购买方式有哪些
- 提升宝清百度SEO排名的实用技巧与策略
- 静宁百度SEO排名:提升您网站曝光率的关键策略
- 彭州百度SEO排名的提升策略和实施指南
- 广南百度关键词SEO:提升网站排名的关键策略
- 辽宁关键词优化怎么做论坛营销
- 吉林百度seo排名如何做到让用户满意
- 内黄百度优化服务:提升在线可见性的关键