H5调用ios,安卓手机摄像头和相册

/*
 * 调用ios,安卓手机摄像头和相册
 */
HTML:
<a href="javascript:;" class="file">
    自定义的文本框
    <input id="car_file" type="file" accept="image/*" multiple />
</a>

CSS:
.file {
    position: relative;
    display: inline-block;
    background: #ffffff;/*--#D0EEFF;*/
    border: 1px solid #999;
    border-radius: 0px;
    /*padding: 4px 12px;*/
    overflow: hidden;
    /*color: #1E88C7;*/
    text-decoration: none;
    text-indent: 0;
    /*line-height: 20px;*/
}
.file input {
    position: absolute;
    /*font-size: 100px;*/
    right: 0;
    top: 0;
    opacity: 0;
}

//当文本框改变时
$("#car_file").change(function(){
   readURL(this);
});    

function readURL(input) {
    if(input.files.length>0){
        for(var a=0;a<input.files.length;a++){
            var reader = new FileReader();
            reader.readAsDataURL(input.files[a]);                
            var i=images.length;
            reader.onload = function (e) {
                i++;
                $("#imageDiv").append("<img attr='"+i+"' src='"+e.target.result+"' style='100%;height:100%;margin-top:10px;'/>");
            }
        }
    }
}
原文地址:https://www.cnblogs.com/AnswerTheQuestion/p/8317906.html