HTML 属性:capture
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
capture 属性指定应选择性地捕获新文件,以及应使用哪个设备来捕获由 accept 属性定义的类型的新媒体。
¥The capture attribute specifies that, optionally, a new file should be captured, and which device should be used to capture that new media of a type defined by the accept attribute.
值包括 user 和 environment。file 输入类型支持 capture 属性。
¥Values include user and environment. The capture attribute is supported on the file input type.
如果 accept 属性指示输入应属于这些类型之一,则 capture 属性将其值用作指定使用哪个相机来捕获图片或视频数据的字符串。
¥The capture attribute takes as its value a string that specifies which camera to use for capture of image or video data, if the accept attribute indicates that the input should be of one of those types.
| 值 | 描述 |
|---|---|
user |
应使用面向用户的摄像头和/或麦克风。 |
environment |
应使用朝外的摄像头和/或麦克风 |
注意:捕获以前是一个布尔属性,如果存在,则请求使用设备的媒体捕获设备(例如相机或麦克风)而不是请求文件输入。
¥Note: Capture was previously a Boolean attribute which, if present, requested that the device's media capture device(s) such as camera or microphone be used instead of requesting a file input.
Try it
示例
¥Examples
当设置为文件输入类型时,带有麦克风和摄像头的操作系统将显示一个用户界面,允许从现有文件中进行选择或创建新文件。
¥When set on a file input type, operating systems with microphones and cameras will display a user interface allowing the selection from an existing file or the creating of a new one.
<p>
<label for="soundFile">What does your voice sound like?:</label>
<input type="file" id="soundFile" capture="user" accept="audio/*" />
</p>
<p>
<label for="videoFile">Upload a video:</label>
<input type="file" id="videoFile" capture="environment" accept="video/*" />
</p>
<p>
<label for="imageFile">Upload a photo of yourself:</label>
<input type="file" id="imageFile" capture="user" accept="image/*" />
</p>
请注意,这些在移动设备上效果更好;如果你的设备是台式计算机,你可能会得到一个典型的文件选择器。
¥Note these work better on mobile devices; if your device is a desktop computer, you'll likely get a typical file picker.
规范
| Specification |
|---|
| HTML Media Capture # dfn-capture |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also