<img id="my-image" src=''>
<input type="file" capture="camera" accept="image/*" id="cameraInput0" name="cameraInput" οnchange="chooseImage(this);"/>
var datas = {
};
/*<span style="white-space:pre"> </span>inputfile onchange事件、
*<span style="white-space:pre"> </span>获取图片数据,并将他显示到页面
*/
<pre name="code" class="html">function chooseImage(<span style="font-family: Arial, Helvetica, sans-serif;">files</span><span style="font-family: Arial, Helvetica, sans-serif;">){</span><pre name="code" class="html"><span style="white-space:pre"> </span>datas<span style="font-family: Arial, Helvetica, sans-serif;">.imageObject = files;</span>
files=files.files;
for (var i = 0; i < files.length; i++) {
<span style="white-space:pre"> var file = files[i];
<span style="white-space:pre"> </span>var reader = new FileReader();
<span style="white-space:pre"> </span> reader.onload = function (e) {</span>
<span style="white-space:pre"> $("</span>#<span style="font-family: Arial, Helvetica, sans-serif;">my-image</span><span style="font-family: Arial, Helvetica, sans-serif;">").attr("src",this.result);</span>
<span style="white-space:pre"><span style="white-space:pre"> </span> }
<span style="white-space:pre"> </span> reader.readAsDataURL(file);</span>
<span style="white-space:pre"> </span>}
}
/*
* <span style="white-space:pre"> </span>上传
*/
function upload(){
<span style="white-space:pre"> var formData = new FormData();</span>
<span style="white-space:pre"> </span>var username = '';
<span style="white-space:pre"> formData.append('</span>file<span style="white-space:pre">',</span>datas<span style="white-space:pre">.imageObject.files[0]); </span>//图片数据
<span style="white-space:pre"> formData.append(</span>'<span style="font-family: Arial, Helvetica, sans-serif;">username</span><span style="font-family: Arial, Helvetica, sans-serif;">',</span>'13574747474'<span style="font-family: Arial, Helvetica, sans-serif;">); </span>//存放字段
<span style="white-space:pre"> var xhr = new XMLHttpRequest();</span>
<span style="white-space:pre"> </span>var url =''<span style="white-space:pre"> </span>//上传路径
<span style="white-space:pre"> xhr.open('POST',</span>url<span style="white-space:pre">,true); </span>
<span style="white-space:pre"> xhr.send(formData);</span>
}