使用input標(biāo)簽 type值為file,可以調(diào)用系統(tǒng)默認的照相機双戳、相冊虹蒋、攝像機、錄音功能飒货。
<input type="file" accept="image/" capture="camera">
<input type="file" accept="video/" capture="camcorder">
<input type="file" accept="audio/*" capture="microphone">
accept表示打開的系統(tǒng)文件目錄
capture表示的是系統(tǒng)所捕獲的默認設(shè)備魄衅,camera:照相機;camcorder:攝像機塘辅;microphone:錄音晃虫;
其中還有一個屬性multiple,支持多選扣墩,當(dāng)支持多選時哲银,multiple優(yōu)先級高于capture,所以只用寫成:<input type="file" accept="image/*" multiple>就可.
//拍照按鈕
$('.comm-bottom-photo').click(function(){
$('.select-camera').click();
});
$('.select-camera').on('click',function(){});
function uploadImg() {
$('.select-camera').on('change', function(e) {
$.showLoading("圖片上傳中...");
var eachPicId = createProcessId(5);
var that = $(this);
$(this).attr("id","file" + eachPicId);
var files = e.target.files;
for(var i = 0, f; f = files[i]; i++) {
if(!f.type.match("image.*")) {
$.hideLoading();
$.alert("只能上傳圖片類型","提示")
continue;
}
var fileValue = that.val();
if(!/\.(gif|jpg|png|GIF|JPG|PNG)$/.test(fileValue)){
$.hideLoading();
$.alert("圖片類型必須是jpg/gif/png中的一種","提示")
continue;
}
var reader = new FileReader(); //將文件讀取為 DataURL
reader.readAsDataURL(f);
reader.onload = (function() { //讀取完成后執(zhí)行的事件
return function(e) {
var changeimg = e.target.result;
var str = '<div data-fileId="" class="upload-photo">![](' + changeimg + ')<div class="icon-pic-to"><div class="pic-icon-to"></div></div></div>'
$('.upload-photo-area').html(str);
$('.upload-photo-area').show();
removePic();
showLargeImg();
$('.make-call-btn').attr('pic-id', eachPicId);
};
})(f);
setTimeout(function() {
$("icon-pic-to").on("click",function() {
$(this).parent().remove();
})
},1000);
}
});
}