Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. HTML(超文本标记语言)
  3. HTML 参考
  4. HTML 属性参考
  5. HTML 属性:capture

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

HTML 属性:capture

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

capture 属性可选地指定应捕获一个新文件,以及应使用哪个设备捕获accept 属性所定义类型的新媒体。

可用值包括userenvironment,该属性支持file 输入类型。

如果accept 属性指示输入应为图像或视频数据类型之一,则capture 属性的值为一个字符串,用于指定使用哪个摄像头捕获图像或视频数据。

描述
user应使用面向用户的摄像头和/或麦克风。
environment应使用朝外的摄像头和/或麦克风。

备注:capture 以前是一个布尔属性,如果存在,则要求使用设备自身的媒体捕捉设备(如摄像头或麦克风),而不是要求输入文件。

尝试一下

<label for="selfie">Take a picture of your face:</label><input type="file" name="selfie" accept="image/*" capture="user" /><label for="picture">Take a picture using back facing camera:</label><input  type="file"   name="picture"  accept="image/*"  capture="environment" />
label {  display: block;  margin-top: 1rem;}input {  margin-bottom: 1rem;}

示例

当设置为文件输入类型时,带有麦克风和摄像头的操作系统将显示一个用户界面,允许从现有文件中进行选择或创建新文件。

html
<p>  <label for="soundFile">你的声音是什么样的:</label>  <input type="file" capture="user" accept="audio/*" /></p><p>  <label for="videoFile">上传一个视频:</label>  <input type="file" capture="environment" accept="video/*" /></p><p>  <label for="imageFile">上传一张自己的照片:</label>  <input type="file" capture="user" accept="image/*" /></p>

请注意,这些功能在移动设备上更好用;如果你的设备是台式电脑,你可能会得到一个典型的文件选择器。

规范

Specification
HTML Media Capture
# dfn-capture

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp