html5呼叫手機攝像頭

螞蟻小編發表於2017-04-14

本章節介紹一下html5呼叫手機攝像頭功能。

用html5自帶的 input file=""  ,純html5,並且不涉及到js ,就可以實現。

程式碼如下:

[HTML] 純文字檢視 複製程式碼
<input type="file" accept="image/*" capture="camera">
<input type="file" accept="video/*" capture="camcorder">
<input type="file" accept="audio/*" capture="microphone">

截圖如下:

a:3:{s:3:\"pic\";s:43:\"portal/201704/14/153827jqeetn1k184h3nie.jpg\";s:5:\"thumb\";s:0:\"\";s:6:\"remote\";N;}

capture表示,可以捕獲到系統預設的裝置,比如:camera--照相機;camcorder--攝像機;microphone--錄音。

accept表示,直接開啟系統檔案目錄。

其實html5的input:file標籤還支援一個multiple屬性,表示可以支援多選,如:

[HTML] 純文字檢視 複製程式碼
<input type="file" accept="image/*" multiple>

加上這個multiple後,capture就沒啥用了,因為multiple是專門yong用來支援多選的。

相關文章