手机
当前位置:查字典教程网 >网页设计 >HTML5教程 >html5读取本地文件示例代码
html5读取本地文件示例代码
摘要:html结构样式如下:添加图片从样式上说应不显示input元素的输入框,这时需将input设置为透明样式,然后将其覆盖到button元素上方...

html结构样式如下:

<div>

<button>添加图片</button>

<form>

<input id="logoimg" type="file" multiple accept="image/*" name="logo">

</form>

</div>

<img id="showlogo" src="" alt="">

从样式上说应不显示input元素的输入框,这时需将input设置为透明样式,然后将其覆盖到button元素上方,这时方可实现点击button上传图片。将accepted设置为“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;

top: 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 更新图片颜色示例代码

HTML5 实现一个访问本地文件的实例

html5时钟实现代码

html5 css3网站菜单实现代码

html5图片上传预览示例分享

HTML5注册表单的自动聚焦与占位文本示例代码

Html5实现iPhone开机界面示例代码

html5 Canvas绘制线条 closePath()实例代码

html5 自定义播放器核心代码

html5+css3气泡组件的实现

精品推荐
分类导航