您的位置:首页 > 其它

文件上传框的自定义

2016-02-29 17:53 176 查看
<input style="display: none;" id="photo" type="file" name="photo" accept="image/*" />
<p style="font-size: 40px;" onclick="selectPhoto()">拍照</p>
<img id="photoimg"/>

$(function(){
$("#photo").change(function(e){
var file = e.target.files[0]||e.dataTransfer.files[0];
if(file){
var reader = new FileReader();
reader.onload=function(){
$("#photoimg").attr("src",this.result);
}

reader.readAsDataURL(file);
}
});
});

function selectPhoto(){
$("#photo").click();
}


如此一来,可以通过点击p标签来选取文件了,可以把p标签自定义成其他样式
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: