現在的h5功能越來越強大。之前做項目時上傳功能input type=file時,在IOS下居然可以直接照相。。。但是在安卓上是不能。后面研究 了下,其實安卓下也可以的。
就是在input上加上capture屬性。至於capture是屬性是什么。查到是下圖這樣解釋。
然后舉個例子。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>html5直接調用手機相機照相/錄像</title> </head> <body> </body> <div> <h3>使用設備的面向用戶的相機拍攝照片</h3> <form> <input type="file" name="image" accept="image/*" capture="user"> <input type="submit" value="照相上傳"> </form> </div> <div> <h3>使用面向環境的設備本地攝像機捕獲視頻:</h3> <form> <input type="file" name="video" accept="video/*" capture="environment"> <input type="submit" value="錄像上傳"> </form> </div> </html>
個人手機測試 了下確實 沒問題