文件上传框的自定义

来源:互联网 发布:json软件 编辑:程序博客网 时间:2024/05/20 06:56
<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标签自定义成其他样式
0 0
原创粉丝点击