<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标签自定义成其他样式