html调用相机相册

2017-11-16  本文已影响493人  Gaochengxin
<!DOCTYPE html>  
<html lang="en">  
  <head>  
      <meta charset="UTF-8">  
      <title>HTML5页面如何在手机端浏览器调用相机、相册功能</title>  
  </head>  
  <body>  

  <div>  
   <input type="file" accept="image/*" value="相机" capture="camera">  
   <input type="file" accept="video/*" value="录像"    capture="camcorder">  
   <input type="file" accept="audio/*" value="录音"    capture="microphone">  
  </div>  
    <script>
        判断ios,如果是ios就去掉capture属性.

       var file = document.querySelector('input');
    if (getIos()) {
        file.removeAttribute("capture");
    }
    function getIos() {
        var ua=navigator.userAgent.toLowerCase();
        if (ua.match(/iPhone\sOS/i) == "iphone os") {
            return true;
        } else {
            return false;
        }
    }
 </script>
  </body>  
  </html> 
上一篇下一篇

猜你喜欢

热点阅读