科技爱好者229 中介绍了 input元素的capture属性

所以去看了一下;

主要说明是 input 元素可以用两个 capture 属性, 具体的值有 userenvironment

  1. user 会采用前置摄像头 or 麦克风
  2. environment 会采用后置摄像头 or 麦克风

摘录一下他们的文档片段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<style>
* {
font-size: 1.5rem;
}
</style>
</head>

<body>
<label for="environment">Capture environment:</label>
<br>
<input
type="file"
id="environment"
capture="environment"
accept="video/*"
>
<br><br>
<label for="user">Capture user:</label>
<br>
<input
type="file"
id="user"
capture="user"
accept="image/*"
>
</body>

</html>